You are here

public function EntityTypeInfo::entityOperation in Form mode manager 8

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

Adds Form Mode Manager operations on entity that supports it.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity on which to define an operation.

Return value

array An array of operation definitions.

See also

hook_entity_operation()

File

src/EntityTypeInfo.php, line 107

Class

EntityTypeInfo
Manipulates entity type information.

Namespace

Drupal\form_mode_manager

Code

public function entityOperation(EntityInterface $entity) {
  $operations = [];
  $form_modes = $this->formModeManager
    ->getFormModesByEntity($entity
    ->getEntityTypeId());
  foreach ($form_modes as $form_mode_name => $form_mode) {
    if ($this
      ->grantAccessToFormModeOperation($form_mode, $entity)) {
      $operations += [
        $form_mode_name => [
          'title' => $this
            ->t('Edit as @form_mode_name', [
            '@form_mode_name' => $form_mode['label'],
          ])
            ->render(),
          'url' => $entity
            ->toUrl("edit-form.{$form_mode_name}"),
          'weight' => 31,
        ],
      ];
    }
  }
  return $operations;
}