Implement better way of setting moderation state

Created on 24 June 2016, almost 9 years ago
Updated 19 February 2025, about 2 months ago

The code in \Drupal\content_moderation\EntityOperations::entityStorageLoad (below) is very iterative and should be reworked into a more functional solution.

  /**
   * Hook bridge.
   *
   * @see hook_entity_storage_load().
   *
   * @param EntityInterface[] $entities
   *   An array of entity objects that have just been loaded.
   * @param string $entity_type_id
   *   The type of entity being loaded, such as "node" or "user".
   */
  public function entityStorageLoad(array $entities, $entity_type_id) {

    // Ensure that all moderatable entities always have a moderation_state field
    // with data, in all translations. That avoids us needing to have a thousand
    // NULL checks elsewhere in the code.

    // Quickly exclude any non-moderatable entities.
    $to_check = array_filter($entities, [$this->moderationInfo, 'isModeratableEntity']);
    if (!$to_check) {
      return;
    }

    // @todo make this more functional, less iterative.
    foreach ($to_check as $entity) {
      foreach ($entity->getTranslationLanguages() as $language) {
        $translation = $entity->getTranslation($language->getId());
        if ($translation->moderation_state->target_id == NULL) {
          $translation->moderation_state->target_id = $this->getDefaultLoadStateId($translation);
        }
      }
    }
  }
📌 Task
Status

Closed: outdated

Version

11.0 🔥

Component

other

Created by

🇬🇧United Kingdom timmillwood 🏴󠁧󠁢󠁷󠁬󠁳󠁿 Wales, UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand quietone

    There is no indication on what this is postponed on. Using git log -S with varying strings from the issue summary, I was not able to find that code in core. Therefore, closing as outdated.

Production build 0.71.5 2024