You are here

function template_preprocess_form_mode_manager_add_list in Form mode manager 8

Prepares variables for list of available entity type templates.

Default template: form-mode-manager-add-list.html.twig.

Parameters

array $variables: An associative array containing:

  • content: An array of content types.

See also

\Drupal\form_mode_manager\Controller\EntityFormModeController::addPage()

File

./form_mode_manager.module, line 75
Contains form_mode_manager.module.

Code

function template_preprocess_form_mode_manager_add_list(array &$variables) {
  $variables['types'] = [];
  $entity_type_id = $variables['entity_type'];

  /** @var \Drupal\form_mode_manager\EntityRoutingMapBase $entity_operation_mapping */
  $entity_operation_mapping = \Drupal::service("plugin.manager.entity_routing_map")
    ->createInstance($entity_type_id, [
    'entityTypeId' => $entity_type_id,
  ]);
  if (!empty($variables['content'])) {

    /** @var \Drupal\Core\Config\Entity\ConfigEntityBundleBase $type */
    foreach ($variables['content'] as $type) {
      $route_name = $entity_operation_mapping
        ->getOperation('add_form') . ".{$variables['form_mode']}";
      $variables['types'][$type
        ->id()] = [
        'type' => $type
          ->id(),
        'add_link' => Link::fromTextAndUrl($type
          ->label(), new Url($route_name, [
          $type
            ->getEntityTypeId() => $type
            ->id(),
        ])),
        'description' => [
          '#markup' => method_exists($type, 'getDescription') ? $type
            ->getDescription() : $type
            ->label(),
        ],
      ];
    }
  }
}