Droplets
Began

I started building websites in 1997... created a custom content management system in 2004, and shifted toward Drupal in 2010. Drupal 8 is a massive improvement over Drupal 7. Drupal 8 is more Object-Oriented, test-friendly & flexible. Code is more portable, and support for third-party vendor PHP libraries help support both the Drupal & PHP communities.

I've had the privilege to contribute to the following Drupal projects through the years...

 

<?php
namespace Drupal\example_module\Form\Batch;

use Drupal\Core\TypedData\TranslatableInterface;
use Drupal\batch_services\BatchWorkerService;

class FooBatchWorkerService extends BatchWorkerService {

  private ExampleHelperServiceInterface $exampleHelper;

  public function __construct(MessengerInterface $messenger, ExampleHelperServiceInterface $exampleHelper)
  {
    parent::__construct($messenger);
    $this->exampleHelper = $exampleHelper;
  }

  /**
   * Gets the batch title.
   */
  public function getTitle(): TranslatableInterface
  {
    return $this->t('Processing Foo items...');
  }

  /**
   * Gets remote items.
   *
   * @param int $page
   *   The human-readable page number (e.g. starting with "1").
   * @param int $limit
   *   How many items to get with each page.
   *
   * @return array
   *   A list of assets & metadata about the query.
   */
  public function getRemoteItems(int $page = 1, int $limit = 100): array
  {
    return [
      'media' => ['foo', 'bar', 'baz'],
      'total' => 3,
    ];
  }

  /**
   * Processes a batch item.
   */
  public function processBatchItem(): void
  {
    $result = $this->getRemoteItems($this->getPageNumber(), static::ITEMS_PER_PAGE);
    $this->setTotal($result['total']['count']);
    foreach ($result['media'] as $asset) {
      if ('baz' === $asset) {
        $this->incrementSkipped();
      }
      else {
        $this->exampleHelper->createMediaEntityFromAsset($asset)->save();
        $this->incrementCreated();
      }
      $this->incrementProgress();
      $this->incrementCurrentId();
    }
  }

}

 

Form Factory

public function buildForm(array $form, FormStateInterface $form_state) {
  $factory = $this->formFactoryService->load($form);
  $k = $this->formFactoryKitsService;

  $factory->append($k->text())
    ->append($k->submit());

  return $factory->getForm();
}

The Basics

$factory = $this->formFactoryService->load($form);
$k = $this->formFactoryKitsService;

// Create a `textfield` field.
$factory->append($k->text());

// Create a `managed_file` field.
$factory->append($k->file());

// Create a `submit` button.
$factory->append($k->submit());

// Build the render array.
$form = $factory->getForm();

 

/** @var \Drupal\query\Services\QueryInterface $q */
$q = \Drupal::service('query');
$result = example_get_events([
  $q->condition()
    ->key('type')
    ->isEqualTo('event'),
  $q->condition()
    ->key('published')
    ->is(),
  $q->condition()
    ->key('month')
    ->isBetween(2, 10)
    ->isNotIn([3,5,7]),
]);