You are here

public function EntityFormBlockDeriver::getDerivativeDefinitions in Flexiform 8

@todo: Contstrain contexts by bundle.

Overrides DeriverBase::getDerivativeDefinitions

File

src/Plugin/Deriver/EntityFormBlockDeriver.php, line 85

Class

EntityFormBlockDeriver
Provides a deriver class.

Namespace

Drupal\flexiform\Plugin\Deriver

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {
    if (!$entity_type
      ->isSubclassOf('\\Drupal\\Core\\Entity\\FieldableEntityInterface')) {
      continue;
    }
    foreach ($this->entityBundleInfo
      ->getBundleInfo($entity_type_id) as $bundle => $bundle_info) {
      $values = [];
      if ($entity_type
        ->hasKey('bundle')) {
        $values[$entity_type
          ->getKey('bundle')] = $bundle;
      }
      foreach ($this->entityDisplayRepository
        ->getFormModeOptions($entity_type_id) as $mode_name => $mode_label) {

        /* @var \Drupal\flexiform\FlexiformEntityFormDisplayInterface $entity_form_display */
        $entity_form_display = FlexiformEntityFormDisplay::collectRenderDisplayLight($entity_type_id, $bundle, $mode_name);
        $plugin_id = "{$entity_type_id}.{$bundle}.{$mode_name}";
        $this->derivatives[$plugin_id] = [
          'admin_label' => $this
            ->t('@entity_type (@bundle) @mode form', [
            '@entity_type' => $entity_type
              ->getLabel(),
            '@bundle' => $bundle_info['label'],
            '@mode' => $mode_label,
          ]),
          'entity_type' => $entity_type_id,
          'bundle' => $bundle,
          'form_mode' => $mode_name,
          'context' => [
            'entity' => new ContextDefinition('entity:' . $entity_type_id, $this
              ->t('Base @entity_type', [
              '@entity_type' => $entity_type
                ->getLabel(),
            ])),
          ],
        ] + $base_plugin_definition;
        foreach ($entity_form_display
          ->getFormEntityConfig() as $namespace => $form_entity_info) {
          if ($form_entity_info['plugin'] != 'provided') {
            continue;
          }
          $this->derivatives[$plugin_id]['context'][$namespace] = new ContextDefinition('entity:' . $form_entity_info['entity_type'], $form_entity_info['label']);
        }
      }
    }
  }
  return $this->derivatives;
}