You are here

public function ConfigEntityRevisionsConfigEntityTrait::__construct in Config Entity Revisions 8.2

Constructs an Entity object.

Parameters

array $values: An array of values to set, keyed by property name. If the entity type has bundles, the bundle key has to be specified.

string $entity_type: The type of the entity to create.

1 method overrides ConfigEntityRevisionsConfigEntityTrait::__construct()
ContactFormRevisions::__construct in modules/contact_form_revisions/src/Entity/ContactFormRevisions.php
Constructs an Entity object.

File

src/ConfigEntityRevisionsConfigEntityTrait.php, line 68

Class

ConfigEntityRevisionsConfigEntityTrait
Trait ConfigEntityRevisionsConfigEntityTrait.

Namespace

Drupal\config_entity_revisions

Code

public function __construct(array $values, $entity_type) {
  parent::__construct($values, $entity_type);
  $this->entityTypeManager = \Drupal::service('entity_type.manager');

  // Add moderation info field.
  $entity_type_info = ConfigEntityRevisionsEntityTypeInfo::create(\Drupal::getContainer());
  $moderation_fields = $entity_type_info
    ->entityExtraFieldInfo();
  if (!empty($moderation_fields['config_entity_revisions'][$this
    ->getBundleName()]) && $this
    ->getContentEntity()) {

    // NB: By feeding the content entity as the parent, we dont need to
    // override the ModerationStateFieldItemList class.
    $entity_adapter = EntityAdapter::createFromEntity($this
      ->getContentEntity());
    $definition = ListDataDefinition::createFromItemType('field_item:string');
    $this->moderation_state = ModerationStateFieldItemList::createInstance($definition, 'moderation_state', $entity_adapter);
  }
}