You are here

protected function LingotekContentMetadataFieldItemList::getContentMetadata in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/LingotekContentMetadataFieldItemList.php \Drupal\lingotek\Plugin\Field\LingotekContentMetadataFieldItemList::getContentMetadata()
  2. 4.0.x src/Plugin/Field/LingotekContentMetadataFieldItemList.php \Drupal\lingotek\Plugin\Field\LingotekContentMetadataFieldItemList::getContentMetadata()
  3. 3.0.x src/Plugin/Field/LingotekContentMetadataFieldItemList.php \Drupal\lingotek\Plugin\Field\LingotekContentMetadataFieldItemList::getContentMetadata()
  4. 3.1.x src/Plugin/Field/LingotekContentMetadataFieldItemList.php \Drupal\lingotek\Plugin\Field\LingotekContentMetadataFieldItemList::getContentMetadata()
  5. 3.2.x src/Plugin/Field/LingotekContentMetadataFieldItemList.php \Drupal\lingotek\Plugin\Field\LingotekContentMetadataFieldItemList::getContentMetadata()
  6. 3.3.x src/Plugin/Field/LingotekContentMetadataFieldItemList.php \Drupal\lingotek\Plugin\Field\LingotekContentMetadataFieldItemList::getContentMetadata()
  7. 3.5.x src/Plugin/Field/LingotekContentMetadataFieldItemList.php \Drupal\lingotek\Plugin\Field\LingotekContentMetadataFieldItemList::getContentMetadata()
  8. 3.6.x src/Plugin/Field/LingotekContentMetadataFieldItemList.php \Drupal\lingotek\Plugin\Field\LingotekContentMetadataFieldItemList::getContentMetadata()
  9. 3.7.x src/Plugin/Field/LingotekContentMetadataFieldItemList.php \Drupal\lingotek\Plugin\Field\LingotekContentMetadataFieldItemList::getContentMetadata()
  10. 3.8.x src/Plugin/Field/LingotekContentMetadataFieldItemList.php \Drupal\lingotek\Plugin\Field\LingotekContentMetadataFieldItemList::getContentMetadata()

Gets the Lingotek metadata entity linked to a content entity revision.

Return value

\Drupal\lingotek\LingotekContentMetadataInterface|null The content entity's Lingotek metadata.

2 calls to LingotekContentMetadataFieldItemList::getContentMetadata()
LingotekContentMetadataFieldItemList::computeLingotekMetadataFieldItemList in src/Plugin/Field/LingotekContentMetadataFieldItemList.php
Recalculate the Lingotek metadata field item list.
LingotekContentMetadataFieldItemList::preSave in src/Plugin/Field/LingotekContentMetadataFieldItemList.php
Defines custom presave behavior for field values.

File

src/Plugin/Field/LingotekContentMetadataFieldItemList.php, line 19

Class

LingotekContentMetadataFieldItemList
A computed field that provides a content entity's Lingotek metadata.

Namespace

Drupal\lingotek\Plugin\Field

Code

protected function getContentMetadata() {
  $entity = $this
    ->getEntity();

  /** @var LingotekConfigurationServiceInterface $config_service */
  $config_service = \Drupal::service('lingotek.configuration');
  if (!$config_service
    ->isEnabled($entity
    ->getEntityTypeId(), $entity
    ->bundle())) {
    return NULL;
  }
  if ($entity
    ->id()) {
    $metadata_result = \Drupal::entityTypeManager()
      ->getStorage('lingotek_content_metadata')
      ->getQuery()
      ->condition('content_entity_type_id', $entity
      ->getEntityTypeId())
      ->condition('content_entity_id', $entity
      ->id())
      ->execute();
    if ($metadata_id = key($metadata_result)) {

      /** @var \Drupal\lingotek\LingotekContentMetadataInterface $metadata */
      $metadata = \Drupal::entityTypeManager()
        ->getStorage('lingotek_content_metadata')
        ->load($metadata_id);
      return $metadata;
    }
  }
  $metadata = LingotekContentMetadata::create();
  if ($entity
    ->id()) {
    $metadata
      ->setEntity($entity);
    $metadata
      ->save();
  }
}