You are here

public function FormModeManager::getActiveDisplays in Form mode manager 8

Same name and namespace in other branches
  1. 8.2 src/FormModeManager.php \Drupal\form_mode_manager\FormModeManager::getActiveDisplays()

Returns entity (form) displays for the current entity display type.

Parameters

string $entity_type_id: The entity type ID to check active modes.

Return value

array The Display mode id for defined entity_type_id.

Overrides FormModeManagerInterface::getActiveDisplays

File

src/FormModeManager.php, line 84

Class

FormModeManager
FormDisplayManager service.

Namespace

Drupal\form_mode_manager

Code

public function getActiveDisplays($entity_type_id) {
  $load_ids = [];
  $form_mode_ids = [];

  /** @var \Drupal\Core\Config\Entity\ConfigEntityType $entity_type */
  $entity_type = $this->entityTypeManager
    ->getDefinition('entity_form_display');
  $config_prefix = $entity_type
    ->getConfigPrefix();
  $ids = $this->configFactory
    ->listAll($config_prefix . '.' . $entity_type_id . '.');
  foreach ($ids as $id) {
    $config_id = str_replace($config_prefix . '.', '', $id);
    list(, , $form_mode_name) = explode('.', $config_id);
    if ($form_mode_name != 'default') {
      $load_ids[] = $config_id;
    }
  }

  /** @var \Drupal\Core\Entity\Entity\EntityFormDisplay[] $entity_storage */
  $entity_storage = $this->entityTypeManager
    ->getStorage($entity_type
    ->id())
    ->loadMultiple($load_ids);
  foreach ($entity_storage as $form_mode) {
    $form_mode_ids[$form_mode
      ->getMode()] = $form_mode;
  }
  return $form_mode_ids;
}