class EntityTypeInfo implements ContainerInjectionInterface (View source)

internal  
 

Manipulates entity type information.

This class contains primarily bridged hooks for compile-time or cache-clear-time hooks. Runtime hooks should be placed in EntityOperations.

Traits

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected ModerationInformationInterface $moderationInfo

The moderation information service.

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected EntityTypeBundleInfoInterface $bundleInfo

The bundle information service.

protected AccountInterface $currentUser

The current user.

protected StateTransitionValidationInterface $validator

The state transition validation service.

protected array $moderationHandlers

A keyed array of custom moderation handlers for given entity types.

Methods

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__construct(TranslationInterface $translation, ModerationInformationInterface $moderation_information, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $bundle_info, AccountInterface $current_user, StateTransitionValidationInterface $validator)

EntityTypeInfo constructor.

static 
create(ContainerInterface $container)

Instantiates a new instance of this class.

entityTypeAlter(array $entity_types)

Adds Moderation configuration to appropriate entity types.

addModerationToEntityType(ContentEntityTypeInterface $type)

Modifies an entity definition to include moderation support.

array
entityExtraFieldInfo()

Gets the "extra fields" for a bundle.

getModeratedBundles()

Returns an iterable list of entity names and bundle names under moderation.

entityBaseFieldInfo(EntityTypeInterface $entity_type)

Adds base field info to an entity type.

entityPrepareForm(EntityInterface $entity, string $operation, FormStateInterface $form_state)

Replaces the entity form entity object with a proper revision object.

formAlter(array $form, FormStateInterface $form_state, string $form_id)

Alters bundle forms to enforce revision handling.

bool
isModeratedEntityEditForm(FormInterface $form_object)

Checks whether the specified form allows to edit a moderated entity.

static 
bundleFormRedirect(array $form, FormStateInterface $form_state)

Redirect content entity edit forms on save, if there is a pending revision.

Details

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__construct(TranslationInterface $translation, ModerationInformationInterface $moderation_information, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $bundle_info, AccountInterface $current_user, StateTransitionValidationInterface $validator)

EntityTypeInfo constructor.

Parameters

TranslationInterface $translation

The translation service. for form alters.

ModerationInformationInterface $moderation_information

The moderation information service.

EntityTypeManagerInterface $entity_type_manager

Entity type manager.

EntityTypeBundleInfoInterface $bundle_info

Bundle information service.

AccountInterface $current_user

Current user.

StateTransitionValidationInterface $validator

State transition validator.

static create(ContainerInterface $container)

Instantiates a new instance of this class.

This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this instance should use.

entityTypeAlter(array $entity_types)

Adds Moderation configuration to appropriate entity types.

Parameters

array $entity_types

The master entity type list to alter.

See also

hook_entity_type_alter()

protected ContentEntityTypeInterface addModerationToEntityType(ContentEntityTypeInterface $type)

Modifies an entity definition to include moderation support.

This primarily just means an extra handler. A Generic one is provided, but individual entity types can provide their own as appropriate.

Parameters

ContentEntityTypeInterface $type

The content entity definition to modify.

Return Value

ContentEntityTypeInterface

The modified content entity definition.

array entityExtraFieldInfo()

Gets the "extra fields" for a bundle.

Return Value

array

A nested array of 'pseudo-field' elements. Each list is nested within the following keys: entity type, bundle name, context (either 'form' or 'display'). The keys are the name of the elements as appearing in the renderable array (either the entity form or the displayed entity). The value is an associative array:

  • label: The human readable name of the element. Make sure you sanitize this appropriately.
  • description: A short description of the element contents.
  • weight: The default weight of the element.
  • visible: (optional) The default visibility of the element. Defaults to TRUE.
  • edit: (optional) String containing markup (normally a link) used as the element's 'edit' operation in the administration interface. Only for 'form' context.
  • delete: (optional) String containing markup (normally a link) used as the element's 'delete' operation in the administration interface. Only for 'form' context.

See also

hook_entity_extra_field_info()

protected Generator getModeratedBundles()

Returns an iterable list of entity names and bundle names under moderation.

That is, this method returns a list of bundles that have Content Moderation enabled on them.

Return Value

Generator

A generator, yielding a 2 element associative array:

  • entity: The machine name of an entity type, such as "node" or "block_content".
  • bundle: The machine name of a bundle, such as "page" or "article".

BaseFieldDefinition[] entityBaseFieldInfo(EntityTypeInterface $entity_type)

Adds base field info to an entity type.

Parameters

EntityTypeInterface $entity_type

Entity type for adding base fields to.

Return Value

BaseFieldDefinition[]

New fields added by moderation state.

See also

hook_entity_base_field_info()

entityPrepareForm(EntityInterface $entity, string $operation, FormStateInterface $form_state)

Replaces the entity form entity object with a proper revision object.

Parameters

EntityInterface $entity

The entity being edited.

string $operation

The entity form operation.

FormStateInterface $form_state

The form state.

See also

hook_entity_prepare_form()

formAlter(array $form, FormStateInterface $form_state, string $form_id)

Alters bundle forms to enforce revision handling.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.

string $form_id

The form id.

See also

hook_form_alter()

protected bool isModeratedEntityEditForm(FormInterface $form_object)

Checks whether the specified form allows to edit a moderated entity.

Parameters

FormInterface $form_object

The form object.

Return Value

bool

TRUE if the form should get form moderation, FALSE otherwise.

static bundleFormRedirect(array $form, FormStateInterface $form_state)

Redirect content entity edit forms on save, if there is a pending revision.

When saving their changes, editors should see those changes displayed on the next page.

Parameters

array $form

An associative array containing the structure of the form.

FormStateInterface $form_state

The current state of the form.