本文整理汇总了PHP中Drupal\Core\Entity\EntityTypeManagerInterface::getHandler方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityTypeManagerInterface::getHandler方法的具体用法?PHP EntityTypeManagerInterface::getHandler怎么用?PHP EntityTypeManagerInterface::getHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityTypeManagerInterface
的用法示例。
在下文中一共展示了EntityTypeManagerInterface::getHandler方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: entityPresave
/**
* Acts on an entity and set published status based on the moderation state.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being saved.
*/
public function entityPresave(EntityInterface $entity)
{
if ($entity instanceof ContentEntityInterface && $this->moderationInfo->isModeratableEntity($entity)) {
// @todo write a test for this.
if ($entity->moderation_state->entity) {
$update_default_revision = $entity->moderation_state->entity->isDefaultRevisionState();
$published_state = $entity->moderation_state->entity->isPublishedState();
$this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'moderation')->onPresave($entity, $update_default_revision, $published_state);
}
}
}
示例2: entityPresave
/**
* Acts on an entity and set published status based on the moderation state.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being saved.
*/
public function entityPresave(EntityInterface $entity)
{
if ($entity instanceof ContentEntityInterface && $this->moderationInfo->isModeratableEntity($entity)) {
// @todo write a test for this.
if ($entity->moderation_state->entity) {
$update_default_revision = $entity->moderation_state->entity->isDefaultRevisionState();
$published_state = $entity->moderation_state->entity->isPublishedState();
$this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'moderation')->onPresave($entity, $update_default_revision, $published_state);
$event = new WorkbenchModerationTransitionEvent($entity, isset($entity->original) ? $entity->original->moderation_state->target_id : NULL, $entity->moderation_state->target_id);
$this->eventDispatcher->dispatch(WorkbenchModerationEvents::STATE_TRANSITION, $event);
}
}
}
示例3: createInlineFormHandler
/**
* Creates an instance of the inline form handler for the current entity type.
*/
protected function createInlineFormHandler()
{
if (!isset($this->inlineFormHandler)) {
$target_type = $this->getFieldSetting('target_type');
$this->inlineFormHandler = $this->entityTypeManager->getHandler($target_type, 'inline_form');
}
}
示例4: getViewsData
/**
* Returns the views data.
*
* @return array
* The views data.
*/
public function getViewsData()
{
$data = [];
$data['content_revision_tracker']['table']['group'] = $this->t('Content moderation (tracker)');
$data['content_revision_tracker']['entity_type'] = ['title' => $this->t('Entity type'), 'field' => ['id' => 'standard'], 'filter' => ['id' => 'string'], 'argument' => ['id' => 'string'], 'sort' => ['id' => 'standard']];
$data['content_revision_tracker']['entity_id'] = ['title' => $this->t('Entity ID'), 'field' => ['id' => 'standard'], 'filter' => ['id' => 'numeric'], 'argument' => ['id' => 'numeric'], 'sort' => ['id' => 'standard']];
$data['content_revision_tracker']['langcode'] = ['title' => $this->t('Entity language'), 'field' => ['id' => 'standard'], 'filter' => ['id' => 'language'], 'argument' => ['id' => 'language'], 'sort' => ['id' => 'standard']];
$data['content_revision_tracker']['revision_id'] = ['title' => $this->t('Latest revision ID'), 'field' => ['id' => 'standard'], 'filter' => ['id' => 'numeric'], 'argument' => ['id' => 'numeric'], 'sort' => ['id' => 'standard']];
$entity_types_with_moderation = array_filter($this->entityTypeManager->getDefinitions(), function (EntityTypeInterface $type) {
return $this->moderationInformation->canModerateEntitiesOfEntityType($type);
});
// Add a join for each entity type to the content_revision_tracker table.
foreach ($entity_types_with_moderation as $entity_type_id => $entity_type) {
/** @var \Drupal\views\EntityViewsDataInterface $views_data */
// We need the views_data handler in order to get the table name later.
if ($this->entityTypeManager->hasHandler($entity_type_id, 'views_data') && ($views_data = $this->entityTypeManager->getHandler($entity_type_id, 'views_data'))) {
// Add a join from the entity base table to the revision tracker table.
$base_table = $views_data->getViewsTableForEntityType($entity_type);
$data['content_revision_tracker']['table']['join'][$base_table] = ['left_field' => $entity_type->getKey('id'), 'field' => 'entity_id', 'extra' => [['field' => 'entity_type', 'value' => $entity_type_id]]];
// Some entity types might not be translatable.
if ($entity_type->hasKey('langcode')) {
$data['content_revision_tracker']['table']['join'][$base_table]['extra'][] = ['field' => 'langcode', 'left_field' => $entity_type->getKey('langcode'), 'operation' => '='];
}
// Add a relationship between the revision tracker table to the latest
// revision on the entity revision table.
$data['content_revision_tracker']['latest_revision__' . $entity_type_id] = ['title' => $this->t('@label latest revision', ['@label' => $entity_type->getLabel()]), 'group' => $this->t('@label revision', ['@label' => $entity_type->getLabel()]), 'relationship' => ['id' => 'standard', 'label' => $this->t('@label latest revision', ['@label' => $entity_type->getLabel()]), 'base' => $this->getRevisionViewsTableForEntityType($entity_type), 'base field' => $entity_type->getKey('revision'), 'relationship field' => 'revision_id', 'extra' => [['left_field' => 'entity_type', 'value' => $entity_type_id]]]];
// Some entity types might not be translatable.
if ($entity_type->hasKey('langcode')) {
$data['content_revision_tracker']['latest_revision__' . $entity_type_id]['relationship']['extra'][] = ['left_field' => 'langcode', 'field' => $entity_type->getKey('langcode'), 'operation' => '='];
}
}
}
// Provides a relationship from moderated entity to its moderation state
// entity.
$content_moderation_state_entity_type = \Drupal::entityTypeManager()->getDefinition('content_moderation_state');
$content_moderation_state_entity_base_table = $content_moderation_state_entity_type->getDataTable() ?: $content_moderation_state_entity_type->getBaseTable();
$content_moderation_state_entity_revision_base_table = $content_moderation_state_entity_type->getRevisionDataTable() ?: $content_moderation_state_entity_type->getRevisionTable();
foreach ($entity_types_with_moderation as $entity_type_id => $entity_type) {
$table = $entity_type->getDataTable() ?: $entity_type->getBaseTable();
$data[$table]['moderation_state'] = ['title' => t('Moderation state'), 'relationship' => ['id' => 'standard', 'label' => $this->t('@label moderation state', ['@label' => $entity_type->getLabel()]), 'base' => $content_moderation_state_entity_base_table, 'base field' => 'content_entity_id', 'relationship field' => $entity_type->getKey('id'), 'join_extra' => [['field' => 'content_entity_type_id', 'value' => $entity_type_id], ['field' => 'content_entity_revision_id', 'left_field' => $entity_type->getKey('revision')]]]];
$revision_table = $entity_type->getRevisionDataTable() ?: $entity_type->getRevisionTable();
$data[$revision_table]['moderation_state'] = ['title' => t('Moderation state'), 'relationship' => ['id' => 'standard', 'label' => $this->t('@label moderation state', ['@label' => $entity_type->getLabel()]), 'base' => $content_moderation_state_entity_revision_base_table, 'base field' => 'content_entity_revision_id', 'relationship field' => $entity_type->getKey('revision'), 'join_extra' => [['field' => 'content_entity_type_id', 'value' => $entity_type_id]]]];
}
return $data;
}
示例5: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
// If moderation is enabled, revisions MUST be enabled as well.
// Otherwise we can't have forward revisions.
if ($form_state->getValue('enable_moderation_state')) {
/* @var ConfigEntityTypeInterface $bundle */
$bundle = $form_state->getFormObject()->getEntity();
$this->entityTypeManager->getHandler($bundle->getEntityType()->getBundleOf(), 'moderation')->onBundleModerationConfigurationFormSubmit($bundle);
}
parent::submitForm($form, $form_state);
drupal_set_message($this->t('Your settings have been saved.'));
}
示例6: entityPresave
/**
* Acts on an entity and set published status based on the moderation state.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being saved.
*/
public function entityPresave(EntityInterface $entity)
{
if (!$this->moderationInfo->isModeratedEntity($entity)) {
return;
}
if ($entity->moderation_state->target_id) {
$moderation_state = $this->entityTypeManager->getStorage('moderation_state')->load($entity->moderation_state->target_id);
$published_state = $moderation_state->isPublishedState();
// This entity is default if it is new, the default revision, or the
// default revision is not published.
$update_default_revision = $entity->isNew() || $moderation_state->isDefaultRevisionState() || !$this->isDefaultRevisionPublished($entity);
// Fire per-entity-type logic for handling the save process.
$this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'moderation')->onPresave($entity, $update_default_revision, $published_state);
}
}
示例7: bundleFormAlter
/**
* Alters bundle forms to enforce revision handling.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param string $form_id
* The form id.
*
* @see hook_form_alter()
*/
public function bundleFormAlter(array &$form, FormStateInterface $form_state, $form_id)
{
if ($this->moderationInfo->isRevisionableBundleForm($form_state->getFormObject())) {
/* @var ConfigEntityTypeInterface $bundle */
$bundle = $form_state->getFormObject()->getEntity();
$this->entityTypeManager->getHandler($bundle->getEntityType()->getBundleOf(), 'moderation')->enforceRevisionsBundleFormAlter($form, $form_state, $form_id);
} else {
if ($this->moderationInfo->isModeratedEntityForm($form_state->getFormObject())) {
/* @var ContentEntityInterface $entity */
$entity = $form_state->getFormObject()->getEntity();
$this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'moderation')->enforceRevisionsEntityFormAlter($form, $form_state, $form_id);
// Submit handler to redirect to the
#$form['actions']['submit']['#submit'][] = [$this, 'bundleFormRedirect'];
}
}
}
示例8: formAlter
/**
* Alters bundle forms to enforce revision handling.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param string $form_id
* The form id.
*
* @see hook_form_alter()
*/
public function formAlter(array &$form, FormStateInterface $form_state, $form_id)
{
$form_object = $form_state->getFormObject();
if ($form_object instanceof BundleEntityFormBase) {
$type = $form_object->getEntity()->getEntityType();
if ($this->moderationInfo->canModerateEntitiesOfEntityType($type)) {
$this->entityTypeManager->getHandler($type->getBundleOf(), 'moderation')->enforceRevisionsBundleFormAlter($form, $form_state, $form_id);
}
} elseif ($form_object instanceof ContentEntityFormInterface) {
$entity = $form_object->getEntity();
if ($this->moderationInfo->isModeratedEntity($entity)) {
$this->entityTypeManager->getHandler($entity->getEntityTypeId(), 'moderation')->enforceRevisionsEntityFormAlter($form, $form_state, $form_id);
// Submit handler to redirect to the latest version, if available.
$form['actions']['submit']['#submit'][] = [EntityTypeInfo::class, 'bundleFormRedirect'];
}
}
}
示例9: getFallbackViewBuilder
/**
* Gets the original view builder for this entity.
*
* @return \Drupal\Core\Entity\EntityViewBuilderInterface
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
protected function getFallbackViewBuilder()
{
return $this->entityTypeManager->getHandler($this->entityTypeId, 'fallback_view_builder');
}
示例10: initializeIefController
/**
* Initializes IEF form handler.
*/
protected function initializeIefController() {
if (!isset($this->iefHandler)) {
$target_type = $this->fieldDefinition->getFieldStorageDefinition()->getSetting('target_type');
$this->iefHandler = $this->entityTypeManager->getHandler($target_type, 'inline_form');
}
}