本文整理汇总了PHP中Drupal\Core\Entity\EntityManagerInterface::getDefinition方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManagerInterface::getDefinition方法的具体用法?PHP EntityManagerInterface::getDefinition怎么用?PHP EntityManagerInterface::getDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::getDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: access
/**
* Checks access to the translation overview for the entity and bundle.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The parametrized route.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
* @param string $entity_type_id
* The entity type ID.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(RouteMatchInterface $route_match, AccountInterface $account, $entity_type_id)
{
/* @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $route_match->getParameter($entity_type_id);
if ($entity && $entity->isTranslatable()) {
// Get entity base info.
$bundle = $entity->bundle();
// Get entity access callback.
$definition = $this->entityManager->getDefinition($entity_type_id);
$translation = $definition->get('translation');
$access_callback = $translation['content_translation']['access_callback'];
$access = call_user_func($access_callback, $entity);
if ($access->isAllowed()) {
return $access;
}
// Check "translate any entity" permission.
if ($account->hasPermission('translate any entity')) {
return AccessResult::allowed()->cachePerPermissions()->inheritCacheability($access);
}
// Check per entity permission.
$permission = "translate {$entity_type_id}";
if ($definition->getPermissionGranularity() == 'bundle') {
$permission = "translate {$bundle} {$entity_type_id}";
}
return AccessResult::allowedIfHasPermission($account, $permission)->inheritCacheability($access);
}
// No opinion.
return AccessResult::neutral();
}
示例2: setEnabled
/**
* {@inheritdoc}
*/
public function setEnabled($entity_type_id, $bundle, $value)
{
$config = $this->loadContentLanguageSettings($entity_type_id, $bundle);
$config->setThirdPartySetting('content_translation', 'enabled', $value)->save();
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$this->updatesManager->updateDefinitions(array($entity_type_id => $entity_type));
}
示例3: validateAndUpcastRequestAttributes
/**
* Validates and upcasts request attributes.
*
* @todo Remove once https://drupal.org/node/1837388 is fixed.
*/
protected function validateAndUpcastRequestAttributes(Request $request)
{
// Load the entity.
if (!is_object($entity = $request->attributes->get('entity'))) {
$entity_id = $entity;
$entity_type = $request->attributes->get('entity_type');
if (!$entity_type || !$this->entityManager->getDefinition($entity_type)) {
return FALSE;
}
$entity = $this->entityManager->getStorage($entity_type)->load($entity_id);
if (!$entity) {
return FALSE;
}
$request->attributes->set('entity', $entity);
}
// Validate the field name and language.
$field_name = $request->attributes->get('field_name');
if (!$field_name || !$entity->hasField($field_name)) {
return FALSE;
}
$langcode = $request->attributes->get('langcode');
if (!$langcode || !$entity->hasTranslation($langcode)) {
return FALSE;
}
return TRUE;
}
示例4: setMapperDefinition
/**
* {@inheritdoc}
*/
public function setMapperDefinition($mapper_definition)
{
$this->baseEntityType = $mapper_definition['base_entity_type'];
$this->baseEntityInfo = $this->entityManager->getDefinition($this->baseEntityType);
$this->baseEntityBundles = $this->entityManager->getBundleInfo($this->baseEntityType);
return $this;
}
示例5: form
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state)
{
$form = parent::form($form, $form_state);
$comment_type = $this->entity;
$form['label'] = array('#type' => 'textfield', '#title' => t('Label'), '#maxlength' => 255, '#default_value' => $comment_type->label(), '#required' => TRUE);
$form['id'] = array('#type' => 'machine_name', '#default_value' => $comment_type->id(), '#machine_name' => array('exists' => '\\Drupal\\comment\\Entity\\CommentType::load'), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => !$comment_type->isNew());
$form['description'] = array('#type' => 'textarea', '#default_value' => $comment_type->getDescription(), '#description' => t('Describe this comment type. The text will be displayed on the <em>Comment types</em> administration overview page.'), '#title' => t('Description'));
if ($comment_type->isNew()) {
$options = array();
foreach ($this->entityManager->getDefinitions() as $entity_type) {
// Only expose entities that have field UI enabled, only those can
// get comment fields added in the UI.
if ($entity_type->get('field_ui_base_route')) {
$options[$entity_type->id()] = $entity_type->getLabel();
}
}
$form['target_entity_type_id'] = array('#type' => 'select', '#default_value' => $comment_type->getTargetEntityTypeId(), '#title' => t('Target entity type'), '#options' => $options, '#description' => t('The target entity type can not be changed after the comment type has been created.'));
} else {
$form['target_entity_type_id_display'] = array('#type' => 'item', '#markup' => $this->entityManager->getDefinition($comment_type->getTargetEntityTypeId())->getLabel(), '#title' => t('Target entity type'));
}
if ($this->moduleHandler->moduleExists('content_translation')) {
$form['language'] = array('#type' => 'details', '#title' => t('Language settings'), '#group' => 'additional_settings');
$language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('comment', $comment_type->id());
$form['language']['language_configuration'] = array('#type' => 'language_configuration', '#entity_information' => array('entity_type' => 'comment', 'bundle' => $comment_type->id()), '#default_value' => $language_configuration);
$form['#submit'][] = 'language_configuration_element_submit';
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
return $form;
}
示例6: getDerivativeDefinitions
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition)
{
$this->derivatives = [];
/** @var \Drupal\rng\Entity\EventType[] $event_types */
foreach ($this->eventManager->getEventTypes() as $entity_type => $event_types) {
$cache_tags = $this->entityManager->getDefinition($entity_type)->getListCacheTags();
foreach ($event_types as $event_type) {
$cache_tags = Cache::mergeTags($cache_tags, $event_type->getCacheTags());
}
// Only need one set of tasks task per entity type.
if ($this->routeProvider->getRouteByName("entity.{$entity_type}.canonical")) {
$event_default = "rng.event.{$entity_type}.event.default";
$this->derivatives[$event_default] = array('title' => t('Event'), 'base_route' => "entity.{$entity_type}.canonical", 'route_name' => "rng.event.{$entity_type}.event", 'weight' => 30, 'cache_tags' => $cache_tags);
$this->derivatives["rng.event.{$entity_type}.event.settings"] = array('title' => t('Settings'), 'route_name' => $this->derivatives[$event_default]['route_name'], 'parent_id' => 'rng.local_tasks:' . $event_default, 'weight' => 10, 'cache_tags' => $cache_tags);
$this->derivatives["rng.event.{$entity_type}.event.access"] = array('title' => t('Access'), 'route_name' => "rng.event.{$entity_type}.access", 'parent_id' => 'rng.local_tasks:' . $event_default, 'weight' => 20, 'cache_tags' => $cache_tags);
$this->derivatives["rng.event.{$entity_type}.event.messages"] = array('title' => t('Messages'), 'route_name' => "rng.event.{$entity_type}.messages", 'parent_id' => 'rng.local_tasks:' . $event_default, 'weight' => 30, 'cache_tags' => $cache_tags);
$this->derivatives["rng.event.{$entity_type}.event.group.list"] = array('title' => t('Groups'), 'route_name' => "rng.event.{$entity_type}.group.list", 'parent_id' => 'rng.local_tasks:' . $event_default, 'weight' => 40, 'cache_tags' => $cache_tags);
$this->derivatives["rng.event.{$entity_type}.register.type_list"] = array('route_name' => "rng.event.{$entity_type}.register.type_list", 'base_route' => "entity.{$entity_type}.canonical", 'title' => t('Register'), 'weight' => 40, 'cache_tags' => $cache_tags);
}
}
foreach ($this->derivatives as &$entry) {
$entry += $base_plugin_definition;
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
示例7: createInstance
/**
* {@inheritdoc}
*
* A specific createInstance method is necessary to pass the migration on.
*/
public function createInstance($plugin_id, array $configuration = array(), MigrationInterface $migration = NULL)
{
if (substr($plugin_id, 0, 7) == 'entity:' && !$this->entityManager->getDefinition(substr($plugin_id, 7), FALSE)) {
$plugin_id = 'null';
}
return parent::createInstance($plugin_id, $configuration, $migration);
}
示例8: __construct
/**
* Creates a new NodeType instance.
*
* @param EntityManagerInterface $entity_manager
* The entity manager.
* @param array $configuration
* The plugin configuration, i.e. an array with configuration values keyed
* by configuration option name. The special key 'context' may be used to
* initialize the defined contexts by setting it to an array of context
* values keyed by context names.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
*/
public function __construct(EntityManagerInterface $entity_manager, array $configuration, $plugin_id, $plugin_definition)
{
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityStorage = $entity_manager->getStorage($this->getDerivativeId());
$this->bundleType = $entity_manager->getDefinition($this->getDerivativeId());
$this->bundleOf = $entity_manager->getDefinition($this->bundleType->getBundleOf());
}
示例9: init
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL)
{
parent::init($view, $display, $options);
$this->entityTypeId = $this->definition['entity_type'];
$this->entityType = $this->entityManager->getDefinition($this->entityTypeId);
$this->base_table = $this->entityType->getDataTable() ?: $this->entityType->getBaseTable();
$this->base_field = $this->entityType->getKey('id');
}
示例10: calculateDependencies
/**
* {@inheritdoc}
*/
public function calculateDependencies()
{
// The empty source plugin supports the entity_type constant.
if (isset($this->configuration['constants']['entity_type'])) {
$this->addDependency('module', $this->entityManager->getDefinition($this->configuration['constants']['entity_type'])->getProvider());
}
return $this->dependencies;
}
示例11: addDependencyListsToForm
/**
* Adds form elements to list affected configuration entities.
*
* @param array $form
* The form array to add elements to.
* @param string $type
* The type of dependency being checked. Either 'module', 'theme', 'config'
* or 'content'.
* @param array $names
* The specific names to check. If $type equals 'module' or 'theme' then it
* should be a list of module names or theme names. In the case of 'config'
* or 'content' it should be a list of configuration dependency names.
* @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
* The config manager.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*
* @see \Drupal\Core\Config\ConfigManagerInterface::getConfigEntitiesToChangeOnDependencyRemoval()
*/
protected function addDependencyListsToForm(array &$form, $type, array $names, ConfigManagerInterface $config_manager, EntityManagerInterface $entity_manager)
{
// Get the dependent entities.
$dependent_entities = $config_manager->getConfigEntitiesToChangeOnDependencyRemoval($type, $names);
$entity_types = array();
$form['entity_updates'] = array('#type' => 'details', '#title' => $this->t('Configuration updates'), '#description' => $this->t('The listed configuration will be updated.'), '#open' => TRUE, '#access' => FALSE);
foreach ($dependent_entities['update'] as $entity) {
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
$entity_type_id = $entity->getEntityTypeId();
if (!isset($form['entity_updates'][$entity_type_id])) {
$entity_type = $entity_manager->getDefinition($entity_type_id);
// Store the ID and label to sort the entity types and entities later.
$label = $entity_type->getLabel();
$entity_types[$entity_type_id] = $label;
$form['entity_updates'][$entity_type_id] = array('#theme' => 'item_list', '#title' => $label, '#items' => array());
}
$form['entity_updates'][$entity_type_id]['#items'][$entity->id()] = $entity->label() ?: $entity->id();
}
if (!empty($dependent_entities['update'])) {
$form['entity_updates']['#access'] = TRUE;
// Add a weight key to the entity type sections.
asort($entity_types, SORT_FLAG_CASE);
$weight = 0;
foreach ($entity_types as $entity_type_id => $label) {
$form['entity_updates'][$entity_type_id]['#weight'] = $weight;
// Sort the list of entity labels alphabetically.
ksort($form['entity_updates'][$entity_type_id]['#items'], SORT_FLAG_CASE);
$weight++;
}
}
$form['entity_deletes'] = array('#type' => 'details', '#title' => $this->t('Configuration deletions'), '#description' => $this->t('The listed configuration will be deleted.'), '#open' => TRUE, '#access' => FALSE);
foreach ($dependent_entities['delete'] as $entity) {
$entity_type_id = $entity->getEntityTypeId();
if (!isset($form['entity_deletes'][$entity_type_id])) {
$entity_type = $entity_manager->getDefinition($entity_type_id);
// Store the ID and label to sort the entity types and entities later.
$label = $entity_type->getLabel();
$entity_types[$entity_type_id] = $label;
$form['entity_deletes'][$entity_type_id] = array('#theme' => 'item_list', '#title' => $label, '#items' => array());
}
$form['entity_deletes'][$entity_type_id]['#items'][$entity->id()] = $entity->label() ?: $entity->id();
}
if (!empty($dependent_entities['delete'])) {
$form['entity_deletes']['#access'] = TRUE;
// Add a weight key to the entity type sections.
asort($entity_types, SORT_FLAG_CASE);
$weight = 0;
foreach ($entity_types as $entity_type_id => $label) {
if (isset($form['entity_deletes'][$entity_type_id])) {
$form['entity_deletes'][$entity_type_id]['#weight'] = $weight;
// Sort the list of entity labels alphabetically.
ksort($form['entity_deletes'][$entity_type_id]['#items'], SORT_FLAG_CASE);
$weight++;
}
}
}
}
示例12: enhance
/**
* {@inheritdoc}
*/
public function enhance(array $defaults, Request $request) {
if (($bundle = $this->entityManager->getDefinition($defaults['entity_type_id'])->getBundleEntityType()) && isset($defaults[$bundle])) {
// Field UI 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.
$defaults['bundle'] = $defaults['_raw_variables']->get($bundle);
}
return $defaults;
}
示例13: getFormArgument
/**
* {@inheritdoc}
*/
protected function getFormArgument(RouteMatchInterface $route_match)
{
$form_arg = $route_match->getRouteObject()->getDefault('_entity_wizard');
list($entity_type_id, $operation) = explode('.', $form_arg);
$definition = $this->entityManager->getDefinition($entity_type_id);
$handlers = $definition->getHandlerClasses();
if (empty($handlers['wizard'][$operation])) {
throw new \Exception(sprintf('Unsupported wizard operation %s', $operation));
}
return $handlers['wizard'][$operation];
}
示例14: processRequest
/**
* {@inheritdoc}
*
* @return \Drupal\Core\Entity\EntityInterface|array
*/
public function processRequest(Request $request, RouteMatchInterface $route_match, SerializerInterface $serializer)
{
// Unserialize the content of the request if there is any.
$content = $request->getContent();
if (!empty($content)) {
$entity_type_id = $this->getDerivativeId();
/** @var $entity_type \Drupal\Core\Entity\EntityTypeInterface */
$entity_type = $this->manager->getDefinition($entity_type_id);
return $serializer->deserialize($content, $entity_type->getClass(), $request->getContentType(), ['entity_type' => $entity_type_id]);
}
return [];
}
示例15: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, $entity_type_id = NULL, $bundle = NULL)
{
$entity_type = $this->entityManager->getDefinition($entity_type_id);
$this->bundleEntityType = $entity_type->getBundleEntityType();
if (!isset($form_state['bundle'])) {
if (!$bundle) {
$bundle = $this->getRequest()->attributes->get('_raw_variables')->get($this->bundleEntityType);
}
$form_state['bundle'] = $bundle;
}
$this->entity_type = $entity_type_id;
$this->bundle = $form_state['bundle'];
}