flow-1.0.0-beta8/modules/flow_ui/flow_ui.module

modules/flow_ui/flow_ui.module
<?php

/**
 * @file
 * Flow UI module file.
 */

use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
use Drupal\flow\Entity\FlowInterface;

/**
 * Implements hook_entity_type_build().
 */
function flow_ui_entity_type_build(array &$entity_types) {
  /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
  $flow_type = $entity_types['flow'];
  $flow_type->setFormClass('default', 'Drupal\flow_ui\Form\FlowForm');
  $flow_type->setFormClass('delete', 'Drupal\flow_ui\Form\FlowDeleteForm');
  $flow_type->setListBuilderClass('Drupal\flow_ui\FlowUiListBuilder');
  $flow_type->setLinkTemplate('collection', '/admin/structure/flow');
  $flow_type->set('admin_permission', 'administer flow');
  $flow_type->setHandlerClass('access', 'Drupal\flow_ui\FlowUiAccessControlHandler');
}

/**
 * Implements hook_entity_bundle_create().
 */
function flow_ui_entity_bundle_create() {
  // The menu needs to be rebuilt to add our menu item tabs.
  \Drupal::service('router.builder')->setRebuildNeeded();
  _flow_ui_clear_cached_definitions();
}

/**
 * Implements hook_ENTITY_TYPE_insert() for 'field_config'.
 */
function flow_ui_field_config_insert() {
  _flow_ui_clear_cached_definitions();
}

/**
 * Implements hook_ENTITY_TYPE_insert() for 'field_config'.
 */
function flow_ui_field_config_update() {
  _flow_ui_clear_cached_definitions();
}

/**
 * Implements hook_ENTITY_TYPE_insert() for 'field_storage_config'.
 */
function flow_ui_field_storage_config_insert() {
  _flow_ui_clear_cached_definitions();
}

/**
 * Implements hook_ENTITY_TYPE_update() for 'field_storage_config'.
 */
function flow_ui_field_storage_config_update() {
  _flow_ui_clear_cached_definitions();
}

/**
 * Clears cached definitions to see the most recent Flow components via UI.
 */
function _flow_ui_clear_cached_definitions() {
  // Refresh the task and subject definitions.
  /** @var \Drupal\flow\Plugin\FlowTaskManager $task_manager */
  $task_manager = \Drupal::service('plugin.manager.flow.task');
  $task_manager->clearCachedDefinitions();
  /** @var \Drupal\flow\Plugin\FlowSubjectManager $subject_manager */
  $subject_manager = \Drupal::service('plugin.manager.flow.subject');
  $subject_manager->clearCachedDefinitions();
}

/**
 * Implements hook_entity_operation().
 */
function flow_ui_entity_operation(EntityInterface $entity) {
  $operations = [];
  $info = $entity->getEntityType();
  // Add a "Manage flow" operation when this entity type supports Field UI.
  if (($bundle_of = $info->getBundleOf()) && \Drupal::entityTypeManager()->getDefinition($bundle_of)->get('field_ui_base_route')) {
    $account = \Drupal::currentUser();
    if ($account->hasPermission('administer ' . $bundle_of . ' flow')) {
      $operations['manage-flow'] = [
        'title' => t('Manage flow'),
        'weight' => 50,
        'url' => Url::fromRoute("entity.flow.{$bundle_of}.default", [
          'entity_type_id' => $bundle_of,
          $entity->getEntityTypeId() => $entity->id(),
        ]),
      ];
    }
  }

  return $operations;
}

/**
 * Implements hook_ENTITY_TYPE_insert() for 'flow'.
 */
function flow_ui_flow_insert(FlowInterface $flow) {
  _flow_ui_post_save_custom($flow);
}

/**
 * Implements hook_ENTITY_TYPE_update() for 'flow'.
 */
function flow_ui_flow_update(FlowInterface $flow) {
  _flow_ui_post_save_custom($flow);
}

/**
 * Post saving tasks for custom flow.
 *
 * @param \Drupal\flow\Entity\FlowInterface $flow
 *   The Flow configuration.
 */
function _flow_ui_post_save_custom(FlowInterface $flow): void {
  if (!$flow->isCustom()) {
    return;
  }
  // Reset local tasks cache.
  Cache::invalidateTags(['local_task']);
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc