You are here

protected function AssignmentFormBase::setContentTypeSelect in Features 8.4

Same name and namespace in other branches
  1. 8.3 modules/features_ui/src/Form/AssignmentFormBase.php \Drupal\features_ui\Form\AssignmentFormBase::setContentTypeSelect()

Adds content entity types checkboxes.

1 call to AssignmentFormBase::setContentTypeSelect()
AssignmentBaseForm::buildForm in modules/features_ui/src/Form/AssignmentBaseForm.php
Form constructor.

File

modules/features_ui/src/Form/AssignmentFormBase.php, line 98

Class

AssignmentFormBase
Configures the selected configuration assignment method for this site.

Namespace

Drupal\features_ui\Form

Code

protected function setContentTypeSelect(&$form, $defaults, $type, $exclude_has_config_bundles = TRUE) {
  $entity_types = $this->entityTypeManager
    ->getDefinitions();
  $has_config_bundle = [];
  foreach ($entity_types as $definition) {
    if ($entity_type_id = $definition
      ->getBundleOf()) {
      $has_config_bundle[] = $entity_type_id;
    }
  }
  $options = [];
  foreach ($entity_types as $entity_type_id => $entity_type) {
    if (!$entity_type instanceof ContentEntityTypeInterface) {
      continue;
    }
    if ($exclude_has_config_bundles && in_array($entity_type_id, $has_config_bundle)) {
      continue;
    }
    $options[$entity_type_id] = $entity_type
      ->getLabel() ?: $entity_type_id;
  }

  // Sort the entity types by label.
  uasort($options, 'strnatcasecmp');
  if (!isset($form['types'])) {
    $form['types'] = [
      '#type' => 'container',
      '#tree' => TRUE,
    ];
  }
  $form['types']['content'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Content entity types'),
    '#description' => $this
      ->t('Select content entity types that should be considered @type types.', [
      '@type' => $type,
    ]),
    '#options' => $options,
    '#default_value' => $defaults,
  ];
}