You are here

public function FeatureManageForm::form in Configuration selector 8.2

Same name and namespace in other branches
  1. 8 src/Form/FeatureManageForm.php \Drupal\config_selector\Form\FeatureManageForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/FeatureManageForm.php, line 28

Class

FeatureManageForm
Builds the feature manage form.

Namespace

Drupal\config_selector\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['#title'] = $this
    ->t('Manage @feature', [
    '@feature' => $this->entity
      ->label(),
  ]);
  $form['configuration']['table'] = [
    '#type' => 'table',
    '#header' => [
      $this
        ->t('Configuration entity'),
      $this
        ->t('Description'),
      $this
        ->t('Priority'),
      $this
        ->t('Status'),
      $this
        ->t('Operations'),
    ],
    '#attributes' => [
      'class' => [
        'config-selector--feature-form--table',
      ],
    ],
    '#empty' => $this
      ->t('The feature has no configuration.'),
  ];
  foreach ($this->entity
    ->getConfiguration() as $entity_type_id => $config_entities) {
    $entity_type = $this->entityTypeManager
      ->getDefinition($entity_type_id);
    $form['configuration']['table'][$entity_type_id]['entity_type'] = [
      '#markup' => $entity_type
        ->getPluralLabel(),
      '#wrapper_attributes' => [
        'colspan' => 5,
        'class' => [
          'entity-type',
        ],
        'id' => 'entity-type-' . $entity_type_id,
      ],
    ];

    /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $config_entity */

    // Sort by reverse priority so that the highest priority is listed first.
    $config_entities = array_reverse($this
      ->sortConfigEntities($config_entities), TRUE);
    foreach ($config_entities as $config_entity) {
      $row_id = $config_entity
        ->getConfigDependencyName();
      $form['configuration']['table'][$row_id]['name'] = [
        '#markup' => $config_entity
          ->label(),
        '#wrapper_attributes' => [
          'class' => [
            'entity-label',
          ],
        ],
      ];
      $form['configuration']['table'][$row_id]['description'] = [
        '#markup' => $this
          ->getDescription($config_entity),
      ];
      $form['configuration']['table'][$row_id]['priority'] = [
        '#markup' => $config_entity
          ->getThirdPartySetting('config_selector', 'priority', 0),
      ];
      $form['configuration']['table'][$row_id]['status'] = [
        '#markup' => $config_entity
          ->status() ? $this
          ->t('Enabled') : $this
          ->t('Disabled'),
      ];
      $links = [];
      if (!$config_entity
        ->status()) {
        $links['enable'] = [
          'title' => $this
            ->t('Select'),
          'url' => Url::fromRoute('config_selector.select', [
            'config_selector_feature' => $this->entity
              ->id(),
            'config_entity_type' => $entity_type_id,
            'config_entity_id' => $config_entity
              ->id(),
          ]),
        ];
      }
      if ($config_entity
        ->hasLinkTemplate('edit-form')) {
        $links['edit'] = [
          'title' => $this
            ->t('Edit configuration'),
          'url' => $config_entity
            ->toUrl('edit-form'),
        ];
      }
      $form['configuration']['table'][$row_id]['operations'] = [
        '#type' => 'operations',
        '#links' => $links,
      ];
    }
  }
  $form['#attached']['library'][] = 'config_selector/config_selector.admin';
  return $form;
}