/** * {@inheritdoc} */ protected function alterRoutes(RouteCollection $collection) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { if ($route = $this->getEntityCloneRoute($entity_type)) { $collection->add("entity.$entity_type_id.clone_form", $route); } } }
/** * Sets up the entity type manager to be tested. * * @param \Drupal\Core\Entity\EntityTypeInterface[]|\Prophecy\Prophecy\ProphecyInterface[] $definitions * (optional) An array of entity type definitions. */ protected function setUpEntityTypeDefinitions($definitions = []) { $class = $this->getMockClass(EntityInterface::class); foreach ($definitions as $key => $entity_type) { // \Drupal\Core\Entity\EntityTypeInterface::getLinkTemplates() is called // by \Drupal\Core\Entity\EntityManager::processDefinition() so it must // always be mocked. $entity_type->getLinkTemplates()->willReturn([]); // Give the entity type a legitimate class to return. $entity_type->getClass()->willReturn($class); $definitions[$key] = $entity_type->reveal(); } $this->entityTypeManager->getDefinition(Argument::cetera())->will(function ($args) use($definitions) { $entity_type_id = $args[0]; $exception_on_invalid = $args[1]; if (isset($definitions[$entity_type_id])) { return $definitions[$entity_type_id]; } elseif (!$exception_on_invalid) { return NULL; } else { throw new PluginNotFoundException($entity_type_id); } }); $this->entityTypeManager->getDefinitions()->willReturn($definitions); }
/** * {@inheritdoc} */ protected function alterRoutes(RouteCollection $collection) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { if ($route = $this->getRdfExportRoute($entity_type)) { $collection->add("entity.{$entity_type_id}.rdf_export", $route); $collection->add("entity.{$entity_type_id}.rdf_export_download", $this->getDownloadRoute($entity_type)); } } }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { // Just add support for entity types which have a views integration. if (($base_table = $entity_type->getBaseTable()) && $this->viewsData->get($base_table) && $this->entityTypeManager->hasHandler($entity_type_id, 'view_builder')) { $this->derivatives[$entity_type_id] = array('id' => 'ds_entity:' . $entity_type_id, 'provider' => 'ds', 'title' => 'Display Suite: ' . $entity_type->getLabel(), 'help' => t('Display the @label', array('@label' => $entity_type->getLabel())), 'base' => array($entity_type->getDataTable() ?: $entity_type->getBaseTable()), 'entity_type' => $entity_type_id, 'display_types' => array('normal'), 'class' => $base_plugin_definition['class']); } } return $this->derivatives; }
/** * {@inheritdoc} */ protected function alterRoutes(RouteCollection $collection) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { if ($devel_render = $entity_type->getLinkTemplate('token-devel')) { $options = ['_admin_route' => TRUE, '_token_entity_type_id' => $entity_type_id, 'parameters' => [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]]; $route = new Route($devel_render, ['_controller' => '\\Drupal\\token\\Controller\\TokenDevelController::entityTokens', '_title' => 'Devel Tokens'], ['_permission' => 'access devel information', '_module_dependencies' => 'devel'], $options); $collection->add("entity.{$entity_type_id}.token_devel", $route); } } }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { // Only allow content entities and ignore configuration entities. if (!$entity_type instanceof ContentEntityTypeInterface) { continue; } $this->derivatives["entity:{$entity_type_id}"] = ['label' => $this->t('Create @entity_type path alias', ['@entity_type' => $entity_type->getLowercaseLabel()]), 'category' => $this->t('Path'), 'entity_type_id' => $entity_type_id, 'context' => ['entity' => ContextDefinition::create("entity:{$entity_type_id}")->setLabel($entity_type->getLabel())->setRequired(TRUE)->setDescription($this->t('The @entity_type for which to create a path alias.', ['@entity_type' => $entity_type->getLowercaseLabel()])), 'alias' => ContextDefinition::create('string')->setLabel($this->t('Path alias'))->setRequired(TRUE)->setDescription($this->t("Specify an alternative path by which the content can be accessed. For example, 'about' for an about page. Use a relative path and do not add a trailing slash."))], 'provides' => []] + $base_plugin_definition; } return $this->derivatives; }
/** * {@inheritdoc} */ protected function alterRoutes(RouteCollection $collection) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { if ($route = $this->getDevelLoadRoute($entity_type)) { $collection->add("entity.{$entity_type_id}.devel_load", $route); } if ($route = $this->getDevelRenderRoute($entity_type)) { $collection->add("entity.{$entity_type_id}.devel_render", $route); } } }
/** * Returns an array of entity_clone permissions. * * @return array * The permission list. */ public function permissions() { $permissions = []; foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { $permissions['clone ' . $entity_type_id . ' entity'] = $this->translationManager->translate('Clone all <em>@label</em> entities', [ '@label' => $entity_type->getLabel(), ]); } return $permissions; }
/** * {@inheritdoc} */ public function getEntityTypeMappings() { if (empty($this->entityMappings)) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type => $info) { $this->entityMappings[$entity_type] = $info->get('token_type') ?: $entity_type; } // Allow modules to alter the mapping array. $this->moduleHandler->alter('token_entity_mapping', $this->entityMappings); } return $this->entityMappings; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { // Only allow content entities and ignore configuration entities. if (!$entity_type instanceof ContentEntityTypeInterface) { continue; } $this->derivatives[$entity_type_id] = ['label' => $this->t('Before saving @entity_type', ['@entity_type' => $entity_type->getLowercaseLabel()]), 'category' => $entity_type->getLabel(), 'entity_type_id' => $entity_type_id, 'context' => [$entity_type_id => ['type' => "entity:{$entity_type_id}", 'label' => $entity_type->getLabel()]]] + $base_plugin_definition; } return $this->derivatives; }
/** * {@inheritdoc} */ protected function alterRoutes(RouteCollection $collection) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { $base_table = $entity_type->getBaseTable(); if ($entity_type->get('field_ui_base_route') && !empty($base_table)) { if ($display = $entity_type->getLinkTemplate('display')) { $route = new Route($display, array('_controller' => '\\Drupal\\ds\\Controller\\DsController::contextualTab', '_title' => 'Manage display', 'entity_type_id' => $entity_type_id), array('_field_ui_view_mode_access' => 'administer ' . $entity_type_id . ' display'), array('_admin_route' => TRUE, '_ds_entity_type_id' => $entity_type_id, 'parameters' => array($entity_type_id => array('type' => 'entity:' . $entity_type_id)))); $collection->add("entity.{$entity_type_id}.display", $route); } } } }
/** * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { $form = parent::form($form, $form_state); $lineItemType = $this->entity; // Prepare the list of purchasable entity types. $entityTypes = $this->entityTypeManager->getDefinitions(); $purchasableEntityTypes = array_filter($entityTypes, function ($entityType) { return $entityType->isSubclassOf('\Drupal\commerce\PurchasableEntityInterface'); }); $purchasableEntityTypes = array_map(function ($entityType) { return $entityType->getLabel(); }, $purchasableEntityTypes); // Prepare the list of order types. $orderTypes = $this->entityTypeManager->getStorage('commerce_order_type') ->loadMultiple(); $orderTypes = array_map(function ($orderType) { return $orderType->label(); }, $orderTypes); $form['label'] = [ '#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $lineItemType->label(), '#description' => $this->t('Label for the line item type.'), '#required' => TRUE, ]; $form['id'] = [ '#type' => 'machine_name', '#default_value' => $lineItemType->id(), '#machine_name' => [ 'exists' => '\Drupal\commerce_order\Entity\LineItemType::load', 'source' => ['label'], ], '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, ]; $form['purchasableEntityType'] = [ '#type' => 'select', '#title' => $this->t('Purchasable entity type'), '#default_value' => $lineItemType->getPurchasableEntityType(), '#options' => $purchasableEntityTypes, '#empty_value' => '', '#disabled' => !$lineItemType->isNew(), ]; $form['orderType'] = [ '#type' => 'select', '#title' => $this->t('Order type'), '#default_value' => $lineItemType->getOrderType(), '#options' => $orderTypes, '#required' => TRUE, ]; return $this->protectBundleIdElement($form); }
/** * {@inheritdoc} */ protected function alterRoutes(RouteCollection $collection) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { if ($entity_type->hasLinkTemplate('devel-markup')) { $options = array('_admin_route' => TRUE, '_devel_entity_type_id' => $entity_type_id, 'parameters' => array($entity_type_id => array('type' => 'entity:' . $entity_type_id))); if ($devel_render = $entity_type->getLinkTemplate('devel-markup')) { $route = new Route($devel_render, array('_controller' => '\\Drupal\\ds_devel\\Controller\\DsDevelController::entityMarkup', '_title' => 'Devel Render'), array('_permission' => 'access devel information'), $options); $collection->add("entity.{$entity_type_id}.devel_markup", $route); } } } }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { $this->derivatives = array(); foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { if ($entity_type->hasLinkTemplate('display')) { $this->derivatives["{$entity_type_id}.display_tab"] = array('route_name' => "entity.{$entity_type_id}.display", 'weight' => 10, 'title' => $this->t('Manage display'), 'base_route' => "entity.{$entity_type_id}.canonical"); } } foreach ($this->derivatives as &$entry) { $entry += $base_plugin_definition; } return $this->derivatives; }
/** * Get a list of supported entity types suitable for a select list. * * @return array */ public function getSupportedEntityTypesList() { $definitions = $this->entityTypeManager->getDefinitions(); $supported = []; foreach ($definitions as $definition) { // Only support fieldable entity types. if (!$definition->get('field_ui_base_route')) { continue; } $supported[$definition->id()] = $definition->getLabel(); } return $supported; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { $this->derivatives = array(); foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { $has_markup_path = $entity_type->hasLinkTemplate('devel-markup'); if ($has_markup_path) { $this->derivatives["{$entity_type_id}.devel_markup_tab"] = array('route_name' => "entity.{$entity_type_id}.devel_markup", 'weight' => 100, 'title' => $this->t('Markup'), 'parent_id' => "devel.entities:{$entity_type_id}.devel_tab"); } } foreach ($this->derivatives as &$entry) { $entry += $base_plugin_definition; } return $this->derivatives; }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class); $this->entityTypeManager->getDefinitions()->willReturn([$this->entityTypeId => '']); $this->processPlugin = new LinkUri([], 'link_uri', [], $this->entityTypeManager->reveal()); // Url::fromInternalUri() accesses the path validator from the global // container. // @see \Drupal\Core\Url::fromInternalUri() $this->pathValidator = $this->prophesize(PathValidator::class); $container = new ContainerBuilder(); $container->set('path.validator', $this->pathValidator->reveal()); \Drupal::setContainer($container); }
protected function getConfigTypes() { foreach ($this->entityTypeManager->getDefinitions() as $entity_type => $definition) { if ($definition->isSubclassOf('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) { $this->definitions[$entity_type] = $definition; } } $entity_types = array_map(function ($definition) { return $definition->getLabel(); }, $this->definitions); uasort($entity_types, 'strnatcasecmp'); $config_types = array('system.simple' => $this->trans('commands.config.export.single.options.simple-configuration')) + $entity_types; return $config_types; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { $exclude = ['node']; $this->derivatives = []; foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { if (in_array($entity_type_id, $exclude)) { continue; } if (!$entity_type->hasLinkTemplate('version-history')) { continue; } $this->derivatives[$entity_type_id] = ['route_name' => "entity.{$entity_type_id}.version_history", 'title' => 'Revisions', 'base_route' => "entity.{$entity_type_id}.canonical", 'weight' => 20] + $base_plugin_definition; } return parent::getDerivativeDefinitions($base_plugin_definition); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('pathauto.settings'); $form['enabled_entity_types'] = ['#type' => 'details', '#open' => TRUE, '#title' => $this->t('Enabled entity types'), '#description' => $this->t('Enable to add a path field and allow to define alias patterns for the given type. Disabled types already define a path field themselves or currently have a pattern.'), '#tree' => TRUE]; // Get all applicable entity types. foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { // Disable a checkbox if it already exists and if the entity type has // patterns currently defined or if it isn't defined by us. $patterns_count = \Drupal::entityQuery('pathauto_pattern')->condition('type', 'canonical_entities:' . $entity_type_id)->count()->execute(); if (is_subclass_of($entity_type->getClass(), FieldableEntityInterface::class) && $entity_type->hasLinkTemplate('canonical')) { $field_definitions = $this->entityFieldManager->getBaseFieldDefinitions($entity_type_id); $form['enabled_entity_types'][$entity_type_id] = ['#type' => 'checkbox', '#title' => $entity_type->getLabel(), '#default_value' => isset($field_definitions['path']) || in_array($entity_type_id, $config->get('enabled_entity_types')), '#disabled' => isset($field_definitions['path']) && ($field_definitions['path']->getProvider() != 'pathauto' || $patterns_count)]; } } $form['verbose'] = array('#type' => 'checkbox', '#title' => t('Verbose'), '#default_value' => $config->get('verbose'), '#description' => t('Display alias changes (except during bulk updates).')); $form['separator'] = array('#type' => 'textfield', '#title' => t('Separator'), '#size' => 1, '#maxlength' => 1, '#default_value' => $config->get('separator'), '#description' => t('Character used to separate words in titles. This will replace any spaces and punctuation characters. Using a space or + character can cause unexpected results.')); $form['case'] = array('#type' => 'checkbox', '#title' => t('Character case'), '#default_value' => $config->get('case'), '#description' => t('Convert token values to lowercase.')); $max_length = \Drupal::service('pathauto.alias_storage_helper')->getAliasSchemaMaxlength(); $help_link = ''; if (\Drupal::moduleHandler()->moduleExists('help')) { $help_link = ' ' . t('See <a href=":pathauto-help">Pathauto help</a> for details.', [':pathauto-help' => Url::fromRoute('help.page', ['name' => 'pathauto'])->toString()]); } $form['max_length'] = array('#type' => 'number', '#title' => t('Maximum alias length'), '#size' => 3, '#maxlength' => 3, '#default_value' => $config->get('max_length'), '#min' => 1, '#max' => $max_length, '#description' => t('Maximum length of aliases to generate. 100 is the recommended length. @max is the maximum possible length.', array('@max' => $max_length)) . $help_link); $form['max_component_length'] = array('#type' => 'number', '#title' => t('Maximum component length'), '#size' => 3, '#maxlength' => 3, '#default_value' => $config->get('max_component_length'), '#min' => 1, '#max' => $max_length, '#description' => t('Maximum text length of any component in the alias (e.g., [title]). 100 is the recommended length. @max is the maximum possible length.', ['@max' => $max_length]) . $help_link); $description = t('What should Pathauto do when updating an existing content item which already has an alias?'); if (\Drupal::moduleHandler()->moduleExists('redirect')) { $description .= ' ' . t('The <a href=":url">Redirect module settings</a> affect whether a redirect is created when an alias is deleted.', array(':url' => Url::fromRoute('redirect.settings')->toString())); } else { $description .= ' ' . t('Considering installing the <a href=":url">Redirect module</a> to get redirects when your aliases change.', array(':url' => 'http://drupal.org/project/redirect')); } $form['update_action'] = array('#type' => 'radios', '#title' => t('Update action'), '#default_value' => $config->get('update_action'), '#options' => array(PathautoGeneratorInterface::UPDATE_ACTION_NO_NEW => t('Do nothing. Leave the old alias intact.'), PathautoGeneratorInterface::UPDATE_ACTION_LEAVE => t('Create a new alias. Leave the existing alias functioning.'), PathautoGeneratorInterface::UPDATE_ACTION_DELETE => t('Create a new alias. Delete the old alias.')), '#description' => $description); $form['transliterate'] = array('#type' => 'checkbox', '#title' => t('Transliterate prior to creating alias'), '#default_value' => $config->get('transliterate'), '#description' => t('When a pattern includes certain characters (such as those with accents) should Pathauto attempt to transliterate them into the US-ASCII alphabet?')); $form['reduce_ascii'] = array('#type' => 'checkbox', '#title' => t('Reduce strings to letters and numbers'), '#default_value' => $config->get('reduce_ascii'), '#description' => t('Filters the new alias to only letters and numbers found in the ASCII-96 set.')); $form['ignore_words'] = array('#type' => 'textarea', '#title' => t('Strings to Remove'), '#default_value' => $config->get('ignore_words'), '#description' => t('Words to strip out of the URL alias, separated by commas. Do not use this to remove punctuation.'), '#wysiwyg' => FALSE); $form['punctuation'] = array('#type' => 'fieldset', '#title' => t('Punctuation'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#tree' => TRUE); $punctuation = \Drupal::service('pathauto.alias_cleaner')->getPunctuationCharacters(); foreach ($punctuation as $name => $details) { // Use the value from config if it exists. if ($config->get('punctuation.' . $name) !== NULL) { $details['default'] = $config->get('punctuation.' . $name); } else { // Otherwise use the correct default. $details['default'] = $details['value'] == $config->get('separator') ? PathautoGeneratorInterface::PUNCTUATION_REPLACE : PathautoGeneratorInterface::PUNCTUATION_REMOVE; } $form['punctuation'][$name] = array('#type' => 'select', '#title' => $details['name'] . ' (<code>' . SafeMarkup::checkPlain($details['value']) . '</code>)', '#default_value' => $details['default'], '#options' => array(PathautoGeneratorInterface::PUNCTUATION_REMOVE => t('Remove'), PathautoGeneratorInterface::PUNCTUATION_REPLACE => t('Replace by separator'), PathautoGeneratorInterface::PUNCTUATION_DO_NOTHING => t('No action (do not replace)'))); } return parent::buildForm($form, $form_state); }
/** * Returns an iterable of the config entities representing moderatable content. * * @return EntityTypeInterface[] * An array of just those entity types we care about. */ protected function moderatableEntityTypeDefinitions() { $entity_types = $this->entityTypeManager->getDefinitions(); return array_filter($entity_types, function (EntityTypeInterface $type) use($entity_types) { return $type instanceof ConfigEntityTypeInterface && ($bundle_of = $type->get('bundle_of')) && $entity_types[$bundle_of]->isRevisionable(); }); }
/** * Returns an array of ds extras permissions. * * @return array */ public function extrasPermissions() { $permissions = []; if (\Drupal::config('ds_extras.settings')->get('field_permissions')) { $entities = $this->entityTypeManager->getDefinitions(); foreach ($entities as $entity_type => $info) { // @todo do this on all fields ? // @todo hide switch field if enabled $fields = Ds::getFields($entity_type); foreach ($fields as $key => $finfo) { $permissions['view ' . $key . ' on ' . $entity_type] = array('title' => t('View @field on @entity_type', array('@field' => $finfo['title'], '@entity_type' => $info->getLabel()))); } } } return $permissions; }
/** * Utility to build contextual links for a field-based gallery display. * * @param array $xml_route_info * Associative array of route info used to generate the XML. * @param string $entity_type_id * The entity type for this field instance. * @return array * An associated array of calculated contextual link information. */ protected function buildContextualLinks($xml_route_info, $entity_type_id) { $contextual = array(); // These links won't be reliable unless we have a true field instance. if (!$this->isPseudoInstance()) { // Add a contextual link to view the XML. Note that we include any query // params as route paramaters. These won't be used in the actual route // but they will be preserved as query paramaters on the contextual link // (which may be needed during the XML request). $xml_query = !empty($xml_route_info['options']['query']) ? $xml_route_info['options']['query'] : array(); $contextual['juicebox_xml_field'] = array('route_parameters' => $xml_route_info['route_parameters'] + $xml_query); // Calculate a contextual link that can be used to edit the gallery type. // @see \Drupal\juicebox\Plugin\Derivative\JuiceboxConfFieldContextualLinks::getDerivativeDefinitions() $bundle = $this->fieldDefinition->getTargetBundle(); $display_entity = entity_get_display($entity_type_id, $bundle, $this->viewMode); $contextual['juicebox_conf_field_' . $entity_type_id] = array('route_parameters' => array('view_mode_name' => !$display_entity->status() || $display_entity->isNew() ? 'default' : $this->viewMode)); // Some entity types require that a bundle be added to the route params. $entity_types = $this->entityTypeManager->getDefinitions(); $bundle_entity_type = $entity_types[$entity_type_id]->getBundleEntityType(); if (!empty($bundle_entity_type)) { $contextual['juicebox_conf_field_' . $entity_type_id]['route_parameters'][$bundle_entity_type] = $bundle; } } return $contextual; }
/** * {@inheritdoc} */ public function getAllBundleInfo() { if (empty($this->bundleInfo)) { $langcode = $this->languageManager->getCurrentLanguage()->getId(); if ($cache = $this->cacheGet("entity_bundle_info:{$langcode}")) { $this->bundleInfo = $cache->data; } else { $this->bundleInfo = $this->moduleHandler->invokeAll('entity_bundle_info'); foreach ($this->entityTypeManager->getDefinitions() as $type => $entity_type) { // First look for entity types that act as bundles for others, load them // and add them as bundles. if ($bundle_entity_type = $entity_type->getBundleEntityType()) { foreach ($this->entityTypeManager->getStorage($bundle_entity_type)->loadMultiple() as $entity) { $this->bundleInfo[$type][$entity->id()]['label'] = $entity->label(); } } elseif (!isset($this->bundleInfo[$type])) { $this->bundleInfo[$type][$type]['label'] = $entity_type->getLabel(); } } $this->moduleHandler->alter('entity_bundle_info', $this->bundleInfo); $this->cacheSet("entity_bundle_info:{$langcode}", $this->bundleInfo, Cache::PERMANENT, ['entity_types', 'entity_bundles']); } } return $this->bundleInfo; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { /** * @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */ foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { // Just add support for entity types which have a views integration. if (($base_table = $entity_type->getBaseTable()) && $this->viewsData->get($base_table) && $this->entityManager->hasHandler($entity_type_id, 'view_builder')) { $entity_views_tables = [$base_table => $this->viewsData->get($base_table)]; if ($data_table = $entity_type->getDataTable()) { $entity_views_tables[$data_table] = $this->viewsData->get($data_table); } foreach ($entity_views_tables as $table_id => $entity_views_table) { foreach ($entity_views_table as $key => $field_info) { if ($this->isDateField($field_info)) { $derivative = ['replacements' => ['entity_label' => $entity_type->getLabel(), 'entity_type' => $entity_type_id, 'field_id' => $field_info['entity field'], 'base_table' => $table_id, 'base_field' => $this->getTableBaseField($entity_views_table), 'default_field_id' => $this->getTableDefaultField($entity_views_table, $entity_type_id), 'field_label' => $field_info['title']], 'view_template_id' => 'calendar_base_field']; $this->setDerivative($derivative, $base_plugin_definition); } } } // @todo Loop through all fields attached to this entity type. // The have different base tables that are joined to this table. $this->setConfigurableFieldsDerivatives($entity_type, $base_plugin_definition); } } return $this->derivatives; }
/** * {@inheritdoc} */ protected function alterRoutes(RouteCollection $collection) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { $storage = \Drupal::entityManager()->getStorage($entity_type_id); if ($storage instanceof RdfEntitySparqlStorage) { $definitions = $storage->getGraphDefinitions(); // Default is already covered by the 'view' operation. unset($definitions['default']); foreach ($definitions as $name => $definition) { $definition['name'] = $name; if ($route = $this->getRdfGraphRoute($entity_type, $definition)) { $collection->add("entity.{$entity_type_id}.rdf_draft_{$name}", $route); } } } } }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { $this->derivatives = []; foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { if ($this->moderationInfo->canModerateEntitiesOfEntityType($entity_type)) { $bundle_id = $entity_type->getBundleEntityType(); $this->derivatives["{$bundle_id}.moderation_tab"] = ['route_name' => "entity.{$bundle_id}.moderation", 'title' => $this->t('Manage moderation'), 'base_route' => "entity.{$bundle_id}.edit_form", 'weight' => 30] + $base_plugin_definition; } } $latest_version_entities = array_filter($this->entityTypeManager->getDefinitions(), function (EntityTypeInterface $type) { return $this->moderationInfo->canModerateEntitiesOfEntityType($type) && $type->hasLinkTemplate('latest-version'); }); foreach ($latest_version_entities as $entity_type_id => $entity_type) { $this->derivatives["{$entity_type_id}.latest_version_tab"] = ['route_name' => "entity.{$entity_type_id}.latest_version", 'title' => $this->t('Latest version'), 'base_route' => "entity.{$entity_type_id}.canonical", 'weight' => 1] + $base_plugin_definition; } return $this->derivatives; }
/** * {@inheritdoc} */ public function getDerivativeDefinitions($base_plugin_definition) { // We need a contextual link defined for each entity type (that may contain // a Juicebox gallery) in order to provide a link to the relevant edit // display screen. These link definitions must be unique because the related // route to the edit display screen is different for each entity type. foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { // Only fieldable entity are candidates. if ($entity_type->isSubclassOf('\\Drupal\\Core\\Entity\\ContentEntityInterface')) { $bundle_entity_type = $entity_type->getBundleEntityType(); $type_name = $bundle_entity_type == 'bundle' ? $entity_type_id : $bundle_entity_type; $this->derivatives['juicebox.conf_field_' . $entity_type_id]['title'] = t('Configure galleries of this field instance'); $this->derivatives['juicebox.conf_field_' . $entity_type_id]['route_name'] = 'entity.entity_view_display.' . $entity_type_id . '.view_mode'; $this->derivatives['juicebox.conf_field_' . $entity_type_id]['group'] = 'juicebox_conf_field_' . $entity_type_id; } } return parent::getDerivativeDefinitions($base_plugin_definition); }
/** * Alters the table and field information from hook_views_data(). * * @param array $data * An array of all information about Views tables and fields, collected from * hook_views_data(), passed by reference. * * @see hook_views_data() */ public function alterViewsData(array &$data) { $entity_types_with_moderation = array_filter($this->entityTypeManager->getDefinitions(), function (EntityTypeInterface $type) { return $this->moderationInformation->canModerateEntitiesOfEntityType($type); }); foreach ($entity_types_with_moderation as $type) { $data[$type->getRevisionTable()]['latest_revision'] = ['title' => t('Is Latest Revision'), 'help' => t('Restrict the view to only revisions that are the latest revision of their entity.'), 'filter' => ['id' => 'latest_revision']]; } }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); $container = new ContainerBuilder(); // Register plugin managers used by Rules, but mock some unwanted // dependencies requiring more stuff to loaded. $this->moduleHandler = $this->prophesize(ModuleHandlerInterface::class); // Set all the modules as being existent. $this->enabledModules = new \ArrayObject(); $this->enabledModules['rules'] = TRUE; $this->enabledModules['rules_test'] = TRUE; $enabled_modules = $this->enabledModules; $this->moduleHandler->moduleExists(Argument::type('string'))->will(function ($arguments) use($enabled_modules) { return [$arguments[0], $enabled_modules[$arguments[0]]]; }); // Wed don't care about alter() calls on the module handler. $this->moduleHandler->alter(Argument::any(), Argument::any(), Argument::any(), Argument::any())->willReturn(NULL); $this->cacheBackend = new NullBackend('rules'); $rules_directory = __DIR__ . '/../../..'; $this->namespaces = new \ArrayObject(['Drupal\\rules' => $rules_directory . '/src', 'Drupal\\rules_test' => $rules_directory . '/tests/modules/rules_test/src', 'Drupal\\Core\\TypedData' => $this->root . '/core/lib/Drupal/Core/TypedData', 'Drupal\\Core\\Validation' => $this->root . '/core/lib/Drupal/Core/Validation']); $this->actionManager = new RulesActionManager($this->namespaces, $this->cacheBackend, $this->moduleHandler->reveal()); $this->conditionManager = new ConditionManager($this->namespaces, $this->cacheBackend, $this->moduleHandler->reveal()); $this->rulesExpressionManager = new ExpressionManager($this->namespaces, $this->moduleHandler->reveal()); $this->classResolver = $this->prophesize(ClassResolverInterface::class); $this->typedDataManager = new TypedDataManager($this->namespaces, $this->cacheBackend, $this->moduleHandler->reveal(), $this->classResolver->reveal()); $this->rulesDataProcessorManager = new DataProcessorManager($this->namespaces, $this->moduleHandler->reveal()); $this->aliasManager = $this->prophesize(AliasManagerInterface::class); // Keep the deprecated entity manager around because it is still used in a // few places. $this->entityManager = $this->prophesize(EntityManagerInterface::class); $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class); $this->entityTypeManager->getDefinitions()->willReturn([]); $this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class); $this->entityFieldManager->getBaseFieldDefinitions()->willReturn([]); $this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class); $this->entityTypeBundleInfo->getBundleInfo()->willReturn([]); $this->dataFetcher = new DataFetcher(); $this->dataFilterManager = new DataFilterManager($this->namespaces, $this->moduleHandler->reveal()); $this->placeholderResolver = new PlaceholderResolver($this->dataFetcher, $this->dataFilterManager); $container->set('entity.manager', $this->entityManager->reveal()); $container->set('entity_type.manager', $this->entityTypeManager->reveal()); $container->set('entity_field.manager', $this->entityFieldManager->reveal()); $container->set('entity_type.bundle.info', $this->entityTypeBundleInfo->reveal()); $container->set('context.repository', new LazyContextRepository($container, [])); $container->set('path.alias_manager', $this->aliasManager->reveal()); $container->set('plugin.manager.rules_action', $this->actionManager); $container->set('plugin.manager.condition', $this->conditionManager); $container->set('plugin.manager.rules_expression', $this->rulesExpressionManager); $container->set('plugin.manager.rules_data_processor', $this->rulesDataProcessorManager); $container->set('typed_data_manager', $this->typedDataManager); $container->set('string_translation', $this->getStringTranslationStub()); $container->set('uuid', new Php()); $container->set('typed_data.data_fetcher', $this->dataFetcher); $container->set('typed_data.placeholder_resolver', $this->placeholderResolver); \Drupal::setContainer($container); $this->container = $container; }