Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/custom_forms / src / Form / CustomFormHandlerList.php
Size: Mime:
<?php

namespace Drupal\custom_forms\Form;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\custom_forms\CustomFormsSubmissionHandlerManager;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Form controller for the custom form mail list.
 */
class CustomFormHandlerList extends FormBase {

  /**
   * @var \Drupal\custom_forms\CustomFormsSubmissionHandlerManager
   *   The plugin manager for submission handler plugins.
   */
  protected $pluginManager;

  /**
   * @var \Drupal\Core\Entity\EntityStorageInterface
   *   The storage handler for submission handler entities.
   */
  protected $handlerStorage;

  /**
   * @inheritDoc
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('plugin.manager.custom_forms_submission_handlers'),
      $container->get('entity_type.manager')
    );
  }

  /**
   * @inheritDoc
   */
  public function __construct(CustomFormsSubmissionHandlerManager $pluginManager, EntityTypeManagerInterface $entityTypeManager) {
    $this->pluginManager = $pluginManager;
    $this->handlerStorage = $entityTypeManager->getStorage('custom_form_submission_handler');
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'custom_form_handler_list';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $request      = \Drupal::request();
    $attributes   = $request->attributes;
    /** @var \Drupal\custom_forms\CustomFormInterface $customForm */
    $custom_form   = $attributes->get('custom_form');

    // By default, render the form using system-config-form.html.twig.
    $form['#theme'] = 'system_config_form';

    /** @var \Drupal\custom_forms\Entity\CustomFormSubmissionHandlerInterface[] $handlers */
    $handlers = $this->handlerStorage->loadByProperties([
      'form' => $custom_form->id()
    ]);

    $form['handlers'] = [
      '#type' => 'table',
      '#header' => [
        'label' => $this->t('Label'),
        'type' => $this->t('Type'),
        'operations' => $this->t('Operations')
      ],
      '#empty' => $this->t('No handlers found for %form', ['%form' => $custom_form->label()])
    ];

    foreach ($handlers as $handler) {
      $plugin_definition = $handler->getPluginDefinition();
      $id = $handler->id();
      $form['handlers']['#rows'][$id] = [
        'label' => $handler->label(),
        'type' => $plugin_definition['label'],
      ];



      $form['handlers']['#rows'][$handler->id()]['operations']['data'] = [
        '#type' => 'operations',
        '#links' => [
          'edit' => [
            'title' => $this->t('Edit'),
            'url' => Url::fromRoute('entity.custom_form_submission_handler.edit_form', ['custom_form' => $custom_form->id(), 'custom_form_submission_handler' => $id])
          ],
          'delete' => [
            'title' => $this->t('Delete'),
            'url' => Url::fromRoute('entity.custom_form_submission_handler.delete_form', ['custom_form' => $custom_form->id(), 'custom_form_submission_handler' => $id])
          ],
        ],
      ];
    }

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
  }

}