You are here

function flag_entity_operation in Flag 8.4

Implements hook_entity_operation().

File

./flag.module, line 547
The Flag module.

Code

function flag_entity_operation(\Drupal\Core\Entity\EntityInterface $entity) {
  $operations = [];
  if ($entity instanceof \Drupal\flag\FlagInterface) {
    if (!$entity
      ->status()) {
      $operations['enable'] = [
        'title' => t('Enable'),
        'url' => $entity
          ->toUrl('enable'),
        'weight' => 50,
      ];
    }
    else {
      $operations['disable'] = [
        'title' => t('Disable'),
        'url' => $entity
          ->toUrl('disable'),
        'weight' => 50,
      ];
    }
    $operations['reset'] = [
      'title' => t('Reset'),
      'url' => $entity
        ->toUrl('reset'),
      'weight' => 100,
    ];
  }
  return $operations;
}