/** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $entity_type, $container->get('entity.manager')->getStorage($entity_type->id()), $container->get('date.formatter') ); }
/** * Build the route for the actual download path. */ protected function getDownloadRoute(EntityTypeInterface $entity_type) { $entity_type_id = $entity_type->id(); $route = new Route("/rdf-export/{$entity_type_id}/{{$entity_type_id}}/{export_format}"); $route->addDefaults(['_controller' => '\\Drupal\\rdf_export\\Controller\\RdfExportController::download', '_title' => 'RDF Export'])->addRequirements(['_permission' => 'export rdf metadata'])->setOption('entity_type_id', $entity_type_id)->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]); return $route; }
/** * {@inheritdoc} */ public function isModeratableBundle(EntityTypeInterface $entity_type, $bundle) { if ($bundle_entity = $this->loadBundleEntity($entity_type->getBundleEntityType(), $bundle)) { return $bundle_entity->getThirdPartySetting('workbench_moderation', 'enabled', FALSE); } return FALSE; }
/** * Constructs a new EntityViewBuilder. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. */ public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager) { $this->entityTypeId = $entity_type->id(); $this->entityType = $entity_type; $this->entityManager = $entity_manager; $this->languageManager = $language_manager; }
/** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $container->get('entity.manager'), $container->get('module_handler'), $entity_type->id() ); }
/** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $entity_type, $container->get('entity.manager')->getStorage($entity_type->id()), $container->get('scheduled_updates.update_utils') ); }
/** * {@inheritdoc} */ public function shouldModerateEntitiesOfBundle(EntityTypeInterface $entity_type, $bundle) { if ($bundle_entity = $this->loadBundleEntity($entity_type->getBundleEntityType(), $bundle)) { return $bundle_entity->getThirdPartySetting('content_moderation', 'enabled', FALSE); } return FALSE; }
/** * Constructs a new EntityViewBuilder. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity manager service. * @param \Drupal\panelizer\Plugin\PanelizerEntityManager $panelizer_manager * The Panelizer entity manager. * @param \Drupal\Panels\PanelsDisplayManagerInterface $panels_manager * The Panels display manager. */ public function __construct(EntityTypeInterface $entity_type, EntityTypeManagerInterface $entity_type_manager, PanelizerEntityManager $panelizer_manager, PanelsDisplayManagerInterface $panels_manager) { $this->entityTypeId = $entity_type->id(); $this->entityType = $entity_type; $this->entityTypeManager = $entity_type_manager; $this->panelizerManager = $panelizer_manager; $this->panelsManager = $panels_manager; }
/** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $entity_type, $container->get('entity.manager')->getStorage($entity_type->id()), $container->get('url_generator'), $container->get('string_translation') ); }
/** * {@inheritdoc} */ public function calculateDependencies() { if (!empty($this->configuration['rid'])) { $prefix = $this->entityType->getConfigPrefix() . '.'; $this->addDependency('entity', $prefix . $this->configuration['rid']); } return $this->dependencies; }
/** * Constructs an EntityStorageBase instance. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type definition. */ public function __construct(EntityTypeInterface $entity_type) { $this->entityTypeId = $entity_type->id(); $this->entityType = $entity_type; $this->idKey = $this->entityType->getKey('id'); $this->uuidKey = $this->entityType->getKey('uuid'); $this->entityClass = $this->entityType->getClass(); }
/** * Gets the moderation-form route. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type. * * @return \Symfony\Component\Routing\Route|null * The generated route, if available. */ protected function getModerationFormRoute(EntityTypeInterface $entity_type) { if ($entity_type->hasLinkTemplate('moderation-form') && $entity_type->getFormClass('moderation')) { $entity_type_id = $entity_type->id(); $route = new Route($entity_type->getLinkTemplate('moderation-form')); $route->setDefaults(['_entity_form' => "{$entity_type_id}.moderation", '_title' => 'Moderation'])->setRequirement('_permission', 'administer moderation states')->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]); return $route; } }
/** * Gets the devel render route. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type. * * @return \Symfony\Component\Routing\Route|null * The generated route, if available. */ protected function getDevelRenderRoute(EntityTypeInterface $entity_type) { if ($devel_render = $entity_type->getLinkTemplate('devel-render')) { $entity_type_id = $entity_type->id(); $route = new Route($devel_render); $route->addDefaults(['_controller' => '\\Drupal\\devel\\Controller\\DevelController::entityRender', '_title' => 'Devel Render'])->addRequirements(['_permission' => 'access devel information'])->setOption('_admin_route', TRUE)->setOption('_devel_entity_type_id', $entity_type_id)->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]); return $route; } }
/** * {@inheritdoc} */ public function setUp() { $this->entityTypeId = $this->randomMachineName(); $this->provider = $this->randomMachineName(); $this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface'); $this->entityType->expects($this->any())->method('getProvider')->will($this->returnValue($this->provider)); $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface'); $this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType)); }
protected function addFormRoute(EntityTypeInterface $entity_type) { $route = new Route('entity.' . $entity_type->id() . '.add-form'); $route->setDefault('_controller', '\\Drupal\\content_entity_base\\Entity\\Controller\\EntityBaseController::addForm'); $route->setDefault('_title_callback', '\\Drupal\\content_entity_base\\Entity\\Controller\\EntityBaseController::getAddFormTitle'); $route->setDefault('entity_type', $entity_type->id()); $route->setRequirement('_entity_create_access', $entity_type->id()); return $route; }
/** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $entity_type, $container->get('entity.manager')->getStorage($entity_type->id()), $container->get('theme.manager'), $container->get('form_builder'), $container->get('entity.manager')->getStorage('block_visibility_group'), $container->get('state') ); }
/** * Adds base field info to an entity type. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * Entity type for adding base fields to. * * @return \Drupal\Core\Field\BaseFieldDefinition[] * New fields added by moderation state. */ public function entityBaseFieldInfo(EntityTypeInterface $entity_type) { if ($entity_type->isRevisionable()) { $fields = []; // @todo write a test for this. $fields['moderation_state'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('Moderation state'))->setDescription(t('The moderation state of this piece of content.'))->setSetting('target_type', 'moderation_state')->setTargetEntityTypeId($entity_type->id())->setRevisionable(TRUE)->setDisplayOptions('view', ['label' => 'hidden', 'type' => 'string', 'weight' => -5])->setDisplayOptions('form', ['type' => 'moderation_state_default', 'weight' => 5, 'settings' => []])->addConstraint('ModerationState', [])->setDisplayConfigurable('form', FALSE)->setDisplayConfigurable('view', TRUE); return $fields; } return []; }
/** * Gets the devel load route. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type. * * @return \Symfony\Component\Routing\Route|null * The generated route, if available. */ protected function getRdfGraphRoute(EntityTypeInterface $entity_type, $graph_definition) { if ($rdf_draft = $entity_type->getLinkTemplate('rdf-draft-' . $graph_definition['name'])) { $entity_type_id = $entity_type->id(); $route = new Route($rdf_draft); $route->addDefaults(['_controller' => '\\Drupal\\rdf_draft\\Controller\\RdfController::view', '_title' => (string) t('View @title', ['@title' => (string) $graph_definition['title']])])->addRequirements(['_access_rdf_graph' => 'TRUE'])->setOption('entity_type_id', $entity_type_id)->setOption('graph_name', $graph_definition['name'])->setOption('parameters', [$entity_type_id => ['type' => 'entity:' . $entity_type_id]]); return $route; } return NULL; }
/** * Returns the delete multiple form route. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type. * * @return \Symfony\Component\Routing\Route|null * The generated route, if available. */ protected function deleteMultipleFormRoute(EntityTypeInterface $entity_type) { if ($entity_type->hasLinkTemplate('delete-multiple-form')) { $route = new Route($entity_type->getLinkTemplate('delete-multiple-form')); $route->setDefault('_form', '\\Drupal\\entity\\Form\\DeleteMultiple'); $route->setDefault('entity_type_id', $entity_type->id()); $route->setRequirement('_permission', $entity_type->getAdminPermission()); return $route; } }
/** * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_info * * @return mixed */ protected function permissionLabels(EntityTypeInterface $entity_info) { $labels = $entity_info->get("permission_labels"); if (!isset($labels['singular'])) { $labels['singular'] = $entity_info->getLabel(); } if (!isset($labels['plural'])) { $labels['plural'] = $entity_info->getLabel(); } return $labels; }
/** * @covers ::createInstance * @covers ::__construct */ function testCreateInstance() { $this->entityType->expects($this->any())->method('id')->willReturn('currency'); $entity_manager = $this->getMock(EntityManagerInterface::class); $entity_manager->expects($this->once())->method('getStorage')->with('currency')->willReturn($this->entityStorage); $container = $this->getMock(ContainerInterface::class); $map = array(array('entity.manager', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $entity_manager), array('module_handler', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->moduleHandler), array('string_translation', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $this->stringTranslation)); $container->expects($this->any())->method('get')->willReturnMap($map); $sut = CurrencyLocaleListBuilder::createInstance($container, $this->entityType); $this->assertInstanceOf(CurrencyLocaleListBuilder::class, $sut); }
/** * Returns the add form route. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type. * * @return \Symfony\Component\Routing\Route|null * The generated route, if available. */ protected function addFormRoute(EntityTypeInterface $entity_type) { if ($entity_type->hasLinkTemplate('add-form')) { $route = new Route($entity_type->getLinkTemplate('add-form')); $route->setDefault('_controller', '\\Drupal\\entity\\Controller\\EntityCreateController::addForm'); $route->setDefault('_title_callback', '\\Drupal\\entity\\Controller\\EntityCreateController::addFormTitle'); $route->setDefault('entity_type_id', $entity_type->id()); $route->setRequirement('_entity_create_access', $entity_type->id()); return $route; } }
/** * {@inheritdoc} */ protected function setUp() { $this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface'); $this->entityType->expects($this->any())->method('getProvider')->will($this->returnValue('responsive_image')); $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface'); $this->entityManager->expects($this->any())->method('getDefinition')->with('responsive_image_style')->will($this->returnValue($this->entityType)); $this->breakpointManager = $this->getMock('\\Drupal\\breakpoint\\BreakpointManagerInterface'); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('breakpoint.manager', $this->breakpointManager); \Drupal::setContainer($container); }
/** * {@inheritdoc} */ protected function setUp() { $this->entityType = $this->randomMachineName(); $this->entityInfo = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface'); $this->entityInfo->expects($this->any())->method('getProvider')->will($this->returnValue('entity')); $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface'); $this->uuid = $this->getMock('\\Drupal\\Component\\Uuid\\UuidInterface'); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); \Drupal::setContainer($container); }
/** * Provides the bundle label with a fallback when not defined. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type we are looking the bundle label for. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * The entity bundle label or a fallback label. */ protected function getEntityBundleLabel($entity_type) { if ($label = $entity_type->getBundleLabel()) { return $this->t('@label', ['@label' => $label]); } $fallback = $entity_type->getLabel(); if ($bundle_entity_type = $entity_type->getBundleEntityType()) { // This is a better fallback. $fallback = $this->entityManager->getDefinition($bundle_entity_type)->getLabel(); } return $this->t('@label bundle', ['@label' => $fallback]); }
/** * {@inheritdoc} */ public function setUp() { $this->entityTypeId = $this->randomName(); $this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface'); $this->entityType->expects($this->any())->method('getProvider')->will($this->returnValue('breakpoint')); $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface'); $this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType)); $this->uuid = $this->getMock('\\Drupal\\Component\\Uuid\\UuidInterface'); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('uuid', $this->uuid); \Drupal::setContainer($container); }
/** * Overrides \Drupal\views\Plugin\views\filter\InOperator::getValueOptions(). */ public function getValueOptions() { if (!isset($this->value_options)) { $types = entity_get_bundles($this->entityTypeId); $this->value_title = t('@entity types', array('@entity' => $this->entityType->getLabel())); $options = array(); foreach ($types as $type => $info) { $options[$type] = $info['label']; } asort($options); $this->value_options = $options; } return $this->value_options; }
/** * Retrieves filter information based on user input for the default display. * * @param array $form * The full wizard form array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the wizard form. * * @return array * An array of filter arrays keyed by ID. A sort array contains the options * accepted by a filter handler. */ protected function defaultDisplayFiltersUser(array $form, FormStateInterface $form_state) { $filters = array(); if (($type = $form_state->getValue(array('show', 'type'))) && $type != 'all') { $bundle_key = $this->entityType->getKey('bundle'); // Figure out the table where $bundle_key lives. It may not be the same as // the base table for the view; the taxonomy vocabulary machine_name, for // example, is stored in taxonomy_vocabulary, not taxonomy_term_data. module_load_include('inc', 'views_ui', 'admin'); $fields = Views::viewsDataHelper()->fetchFields($this->base_table, 'filter'); if (isset($fields[$this->base_table . '.' . $bundle_key])) { $table = $this->base_table; } else { foreach ($fields as $field_name => $value) { if ($pos = strpos($field_name, '.' . $bundle_key)) { $table = substr($field_name, 0, $pos); break; } } } $table_data = Views::viewsData()->get($table); // If the 'in' operator is being used, map the values to an array. $handler = $table_data[$bundle_key]['filter']['id']; $handler_definition = Views::pluginManager('filter')->getDefinition($handler); if ($handler == 'in_operator' || is_subclass_of($handler_definition['class'], 'Drupal\\views\\Plugin\\views\\filter\\InOperator')) { $value = array($type => $type); } else { $value = $type; } $filters[$bundle_key] = array('id' => $bundle_key, 'table' => $table, 'field' => $bundle_key, 'value' => $value); } return $filters; }
/** * {@inheritdoc} * * @covers ::__construct() */ protected function setUp() { parent::setUp(); $this->entityType = $this->getMock('Drupal\\Core\\Entity\\EntityTypeInterface'); $this->entityTypeId = 'test_entity_type'; $this->entityType->expects($this->any())->method('getKey')->will($this->returnValueMap(array(array('id', 'id'), array('uuid', 'uuid')))); $this->entityType->expects($this->any())->method('id')->will($this->returnValue($this->entityTypeId)); $this->entityType->expects($this->any())->method('getConfigPrefix')->will($this->returnValue('the_config_prefix')); $this->entityType->expects($this->any())->method('getClass')->will($this->returnValue(get_class($this->getMockEntity()))); $this->entityType->expects($this->any())->method('getListCacheTags')->willReturn(array('test_entity_type_list')); $this->moduleHandler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface'); $this->uuidService = $this->getMock('Drupal\\Component\\Uuid\\UuidInterface'); $this->languageManager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface'); $this->languageManager->expects($this->any())->method('getDefaultLanguage')->will($this->returnValue(new Language(array('langcode' => 'en')))); $this->configFactory = $this->getMock('Drupal\\Core\\Config\\ConfigFactoryInterface'); $this->entityQuery = $this->getMock('Drupal\\Core\\Entity\\Query\\QueryInterface'); $this->entityStorage = $this->getMockBuilder('Drupal\\Core\\Config\\Entity\\ConfigEntityStorage')->setConstructorArgs(array($this->entityType, $this->configFactory, $this->uuidService, $this->languageManager))->setMethods(array('getQuery'))->getMock(); $this->entityStorage->expects($this->any())->method('getQuery')->will($this->returnValue($this->entityQuery)); $this->entityStorage->setModuleHandler($this->moduleHandler); $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface'); $this->entityManager->expects($this->any())->method('getDefinition')->with('test_entity_type')->will($this->returnValue($this->entityType)); $this->cacheBackend = $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface'); $this->typedConfigManager = $this->getMock('Drupal\\Core\\Config\\TypedConfigManagerInterface'); $this->typedConfigManager->expects($this->any())->method('getDefinition')->will($this->returnValue(array('mapping' => array('id' => '', 'uuid' => '', 'dependencies' => '')))); $container = new ContainerBuilder(); $container->set('entity.manager', $this->entityManager); $container->set('config.typed', $this->typedConfigManager); $container->set('cache.test', $this->cacheBackend); $container->setParameter('cache_bins', array('cache.test' => 'test')); \Drupal::setContainer($container); }
/** * {@inheritdoc} */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['id'] = BaseFieldDefinition::create('integer')->setLabel(t('Custom entity ID'))->setDescription(t('The custom entity ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE); $fields['uuid'] = BaseFieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The custom entity UUID.'))->setReadOnly(TRUE); $fields['revision_id'] = BaseFieldDefinition::create('integer')->setLabel(t('Revision ID'))->setDescription(t('The revision ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE); $fields['langcode'] = BaseFieldDefinition::create('language')->setLabel(t('Language'))->setDescription(t('The custom entity language code.'))->setTranslatable(TRUE)->setRevisionable(TRUE)->setDisplayOptions('view', array('type' => 'hidden'))->setDisplayOptions('form', array('type' => 'language_select', 'weight' => 2)); $fields['name'] = BaseFieldDefinition::create('string')->setLabel(t('Administrative Title'))->setDescription(t('A brief description of this @entity_label entry.', ['@entity_label' => $entity_type->getLabel()]))->setRevisionable(TRUE)->setTranslatable(TRUE)->setRequired(TRUE)->setDisplayOptions('form', array('type' => 'string_textfield', 'weight' => -5))->setDisplayConfigurable('form', TRUE); $fields['uid'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('Authored by'))->setDescription(t('The username of the entity author.'))->setRevisionable(TRUE)->setSetting('target_type', 'user')->setDefaultValueCallback('Drupal\\content_entity_base\\Entity\\EntityBase::getCurrentUserId')->setTranslatable(TRUE)->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'author', 'weight' => 0))->setDisplayOptions('form', array('type' => 'entity_reference_autocomplete', 'weight' => 5, 'settings' => array('match_operator' => 'CONTAINS', 'size' => '60', 'placeholder' => '')))->setDisplayConfigurable('form', TRUE); $fields['status'] = BaseFieldDefinition::create('boolean')->setLabel(t('Publishing status'))->setDescription(t('A boolean indicating whether the node is published.'))->setRevisionable(TRUE)->setTranslatable(TRUE)->setDefaultValue(TRUE); $fields['type'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('Entity type (Bundle)'))->setDescription(t('The entity type.'))->setSetting('target_type', $entity_type->getBundleEntityType()); $fields['revision_log'] = BaseFieldDefinition::create('string_long')->setLabel(t('Revision log message'))->setDescription(t('The log entry explaining the changes in this revision.'))->setRevisionable(TRUE); $fields['created'] = BaseFieldDefinition::create('created')->setLabel(t('Created'))->setDescription(t('The time that the entity was created.'))->setTranslatable(TRUE)->setRevisionable(TRUE); $fields['changed'] = BaseFieldDefinition::create('changed')->setLabel(t('Changed'))->setDescription(t('The time that the custom entity was last edited.'))->setTranslatable(TRUE)->setRevisionable(TRUE); $fields['revision_translation_affected'] = BaseFieldDefinition::create('boolean')->setLabel(t('Revision translation affected'))->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))->setReadOnly(TRUE)->setRevisionable(TRUE)->setTranslatable(TRUE); return $fields; }