本文整理汇总了PHP中Drupal\Core\Entity\EntityTypeManagerInterface::getDefinition方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityTypeManagerInterface::getDefinition方法的具体用法?PHP EntityTypeManagerInterface::getDefinition怎么用?PHP EntityTypeManagerInterface::getDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityTypeManagerInterface
的用法示例。
在下文中一共展示了EntityTypeManagerInterface::getDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: access
/**
* Checks access to create an entity of any bundle for the given route.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The parameterized route.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
{
$entity_type_id = $route->getRequirement($this->requirementsKey);
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
$access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type_id);
// In case there is no "bundle" entity key, check create access with no
// bundle specified.
if (!$entity_type->hasKey('bundle')) {
return $access_control_handler->createAccess(NULL, $account, [], TRUE);
}
$access = AccessResult::neutral();
$bundles = array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type_id));
// Include list cache tag as access might change if more bundles are added.
if ($entity_type->getBundleEntityType()) {
$access->addCacheTags($this->entityTypeManager->getDefinition($entity_type->getBundleEntityType())->getListCacheTags());
// Check if the user is allowed to create new bundles. If so, allow
// access, so the add page can show a link to create one.
// @see \Drupal\Core\Entity\Controller\EntityController::addPage()
$bundle_access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type->getBundleEntityType());
$access = $access->orIf($bundle_access_control_handler->createAccess(NULL, $account, [], TRUE));
if ($access->isAllowed()) {
return $access;
}
}
// Check whether an entity of any bundle may be created.
foreach ($bundles as $bundle) {
$access = $access->orIf($access_control_handler->createAccess($bundle, $account, [], TRUE));
// In case there is a least one bundle user can create entities for,
// access is allowed.
if ($access->isAllowed()) {
break;
}
}
return $access;
}
示例2: setUpEntityTypeDefinitions
/**
* 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);
}
示例3: getFields
/**
* {@inheritdoc}
*/
public function getFields($entity_type_id)
{
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
if (!$entity_type->isSubclassOf('\\Drupal\\Core\\Entity\\ContentEntityInterface')) {
return [];
}
$map = $this->getAllFields();
return isset($map[$entity_type_id]) ? $map[$entity_type_id] : [];
}
示例4: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/** @var ScheduledUpdateTypeInterface $entity */
$row['label'] = $entity->label();
$row['target_type'] = $this->entityTypeManager->getDefinition($entity->getUpdateEntityType())->getLabel();
$row['id'] = $entity->id();
// You probably want a few more properties here...
return $row + parent::buildRow($entity);
}
示例5: mapFromStorageRecords
/**
* {@inheritdoc}
*/
protected function mapFromStorageRecords(array $records)
{
$entities = parent::mapFromStorageRecords($records);
$prefix = $this->entityTypeManager->getDefinition('moderation_state')->getConfigPrefix();
/* @var \Drupal\workbench_moderation\ModerationStateTransitionInterface $entity */
foreach ($entities as &$entity) {
$entity->setModerationStateConfigPrefix($prefix);
}
reset($entities);
return $entities;
}
示例6: enhance
/**
* {@inheritdoc}
*/
public function enhance(array $defaults, Request $request)
{
// Entity layout forms only need the actual name of the bundle they're dealing
// with, not an upcasted entity object, so provide a simple way for them
// to get it.
$bundle = $this->entityTypeManager->getDefinition($defaults['entity_type_id'])->getBundleEntityType();
if ($bundle && isset($defaults[$bundle])) {
$defaults['bundle'] = $defaults['_raw_variables']->get($bundle);
}
return $defaults;
}
示例7: loadEntityByConfigTarget
/**
* {@inheritdoc}
*/
public function loadEntityByConfigTarget($entity_type_id, $target)
{
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
// For configuration entities, the config target is given by the entity ID.
// @todo Consider adding a method to allow entity types to indicate the
// target identifier key rather than hard-coding this check. Issue:
// https://www.drupal.org/node/2412983.
if ($entity_type instanceof ConfigEntityTypeInterface) {
$entity = $this->entityTypeManager->getStorage($entity_type_id)->load($target);
} else {
$entity = $this->loadEntityByUuid($entity_type_id, $target);
}
return $entity;
}
示例8: getValueOptions
/**
* {@inheritdoc}
*/
public function getValueOptions()
{
if (!isset($this->valueOptions)) {
$entity_type_id = $this->getEntityType();
$entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
$field_name = $this->getFieldName();
$available_countries = $this->getAvailableCountries($entity_type, $field_name);
$countries = $this->countryRepository->getList();
if (!empty($available_countries)) {
$countries = array_intersect_key($countries, $available_countries);
}
$this->valueOptions = $countries;
}
return $this->valueOptions;
}
示例9: interact
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$config_types = $this->getConfigTypes();
$config_name = $input->getArgument('config-name');
if (!$config_name) {
$config_type = $io->choiceNoList($this->trans('commands.config.export.single.questions.config-type'), array_keys($config_types), $this->trans('commands.config.export.single.options.simple-configuration'));
$config_names = $this->getConfigNames($config_type);
$config_name = $io->choiceNoList($this->trans('commands.config.export.single.questions.config-name'), array_keys($config_names));
if ($config_type !== 'system.simple') {
$definition = $this->entityTypeManager->getDefinition($config_type);
$config_name = $definition->getConfigPrefix() . '.' . $config_name;
}
$input->setArgument('config-name', $config_name);
}
$module = $input->getOption('module');
if ($module) {
$optionalConfig = $input->getOption('optional-config');
if (!$optionalConfig) {
$optionalConfig = $io->confirm($this->trans('commands.config.export.single.questions.optional-config'), true);
$input->setOption('optional-config', $optionalConfig);
}
}
if (!$input->getOption('remove-uuid')) {
$removeUuid = $io->confirm($this->trans('commands.config.export.single.questions.remove-uuid'), true);
$input->setOption('remove-uuid', $removeUuid);
}
}
示例10: buildEntity
/**
* {@inheritDoc}
*/
public function buildEntity(array $form, FormStateInterface $form_state)
{
/** @var \Drupal\pathauto\PathautoPatternInterface $entity */
$entity = parent::buildEntity($form, $form_state);
$default_weight = 0;
$alias_type = $entity->getAliasType();
if ($alias_type->getDerivativeId() && $this->entityTypeManager->hasDefinition($alias_type->getDerivativeId())) {
$entity_type = $alias_type->getDerivativeId();
// First, remove bundle and language conditions.
foreach ($entity->getSelectionConditions() as $condition_id => $condition) {
if (in_array($condition->getPluginId(), ['entity_bundle:' . $entity_type, 'node_type', 'language'])) {
$entity->removeSelectionCondition($condition_id);
}
}
if ($bundles = array_filter((array) $form_state->getValue('bundles'))) {
$default_weight -= 5;
$plugin_id = $entity_type == 'node' ? 'node_type' : 'entity_bundle:' . $entity_type;
$entity->addSelectionCondition(['id' => $plugin_id, 'bundles' => $bundles, 'negate' => FALSE, 'context_mapping' => [$entity_type => $entity_type]]);
}
if ($languages = array_filter((array) $form_state->getValue('languages'))) {
$default_weight -= 5;
$language_mapping = $entity_type . ':' . $this->entityTypeManager->getDefinition($entity_type)->getKey('langcode') . ':language';
$entity->addSelectionCondition(['id' => 'language', 'langcodes' => array_combine($languages, $languages), 'negate' => FALSE, 'context_mapping' => ['language' => $language_mapping]]);
$entity->addRelationship($language_mapping, t('Language'));
}
}
$entity->setWeight($default_weight);
return $entity;
}
示例11: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$entity_type_id = $form_state->getValue('entity_type_id');
$entity_type_plural = $this->entityTypeManager->getDefinition($entity_type_id)->getPluralLabel();
$batch = ['title' => t('Deleting @entity_type_plural', ['@entity_type_plural' => $entity_type_plural]), 'operations' => [[[__CLASS__, 'deleteContentEntities'], [$entity_type_id]]], 'finished' => [__CLASS__, 'moduleBatchFinished'], 'progress_message' => ''];
batch_set($batch);
}
示例12: tableFields
/**
* {@inheritdoc}
*/
public function tableFields($bundles) {
$info = $this->entityTypeManager->getDefinition($this->entityTypeId());
$definitions = $this->entityFieldManager->getBaseFieldDefinitions($this->entityTypeId());
$label_key = $info->getKey('label');
$label_field_label = t('Label');
if ($label_key && isset($definitions[$label_key])) {
$label_field_label = $definitions[$label_key]->getLabel();
}
$bundle_key = $info->getKey('bundle');
$bundle_field_label = t('Type');
if ($bundle_key && isset($definitions[$bundle_key])) {
$bundle_field_label = $definitions[$bundle_key]->getLabel();
}
$fields = [];
$fields['label'] = [
'type' => 'label',
'label' => $label_field_label,
'weight' => 1,
];
if (count($bundles) > 1) {
$fields[$bundle_key] = [
'type' => 'field',
'label' => $bundle_field_label,
'weight' => 2,
];
}
return $fields;
}
示例13: getSourcePrefix
/**
* {@inheritdoc}
*/
public function getSourcePrefix()
{
if (empty($this->prefix)) {
$entity_type = $this->entityTypeManager->getDefinition($this->getEntityTypeId());
$path = $entity_type->getLinkTemplate('canonical');
$this->prefix = substr($path, 0, strpos($path, '{'));
}
return $this->prefix;
}
示例14: getDefaultRevisionId
/**
* {@inheritdoc}
*/
public function getDefaultRevisionId($entity_type_id, $entity_id)
{
if ($storage = $this->entityTypeManager->getStorage($entity_type_id)) {
$revision_ids = $storage->getQuery()->condition($this->entityTypeManager->getDefinition($entity_type_id)->getKey('id'), $entity_id)->sort($this->entityTypeManager->getDefinition($entity_type_id)->getKey('revision'), 'DESC')->range(0, 1)->execute();
if ($revision_ids) {
return array_keys($revision_ids)[0];
}
}
}
示例15: entityOperation
/**
* Adds an operation on bundles that should have a Moderation form.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity on which to define an operation.
*
* @return array
* An array of operation definitions.
*
* @see hook_entity_operation()
*/
public function entityOperation(EntityInterface $entity)
{
$operations = [];
$type = $entity->getEntityType();
$bundle_of = $type->getBundleOf();
if ($this->currentUser->hasPermission('administer moderation states') && $bundle_of && $this->moderationInfo->canModerateEntitiesOfEntityType($this->entityTypeManager->getDefinition($bundle_of))) {
$operations['manage-moderation'] = ['title' => t('Manage moderation'), 'weight' => 27, 'url' => Url::fromRoute("entity.{$type->id()}.moderation", [$entity->getEntityTypeId() => $entity->id()])];
}
return $operations;
}