You are here

function cms_content_sync_show_usage_operation in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x cms_content_sync.module \cms_content_sync_show_usage_operation()
  2. 2.0.x cms_content_sync.module \cms_content_sync_show_usage_operation()

Parameters

\Drupal\Core\Entity\EntityInterface $entity:

Return value

array

Callback function for the show operation entity action.

1 call to cms_content_sync_show_usage_operation()
cms_content_sync_entity_operation_alter in ./cms_content_sync.module
Implements hook_entity_operation_alter().

File

./cms_content_sync.module, line 1834
Module file for cms_content_sync.

Code

function cms_content_sync_show_usage_operation(EntityInterface $entity) {
  $operations = [];
  $flows = PushIntent::getFlowsForEntity($entity, PushIntent::PUSH_ANY);
  if (!count($flows)) {
    return [];
  }
  $status_entities = EntityStatus::getInfosForEntity($entity
    ->getEntityTypeId(), $entity
    ->uuid());
  $is_pushed = FALSE;
  foreach ($status_entities as $status_entity) {
    $last_push = $status_entity
      ->get('last_export')->value;
    if (!is_null($last_push)) {
      $is_pushed = TRUE;
    }
  }

  // Only show the operation for entities which have been pushed.
  if ($is_pushed) {
    $operations['show_usage'] = [
      'title' => t('Show usage'),
      'weight' => 151,
      'attributes' => [
        'class' => [
          'use-ajax',
        ],
        'data-dialog-type' => 'modal',
        'data-dialog-options' => Json::encode([
          'width' => 700,
        ]),
      ],
      'url' => Url::fromRoute('cms_content_sync.show_usage', [
        'entity' => $entity
          ->id(),
        'entity_type' => $entity
          ->getEntityTypeId(),
      ]),
    ];
  }
  return $operations;
}