diff --git a/src/Entity/ScheduledUpdate.php b/src/Entity/ScheduledUpdate.php index be3dbe2..44db922 100644 --- a/src/Entity/ScheduledUpdate.php +++ b/src/Entity/ScheduledUpdate.php @@ -29,7 +29,7 @@ use Drupal\user\UserInterface; * "view_builder" = "Drupal\Core\Entity\EntityViewBuilder", * "list_builder" = "Drupal\scheduled_updates\ScheduledUpdateListBuilder", * "views_data" = "Drupal\scheduled_updates\Entity\ScheduledUpdateViewsData", - * + * "translation" = "Drupal\content_translation\ContentTranslationHandler", * "form" = { * "default" = "Drupal\scheduled_updates\Entity\Form\ScheduledUpdateForm", * "add" = "Drupal\scheduled_updates\Entity\Form\ScheduledUpdateForm", @@ -44,6 +44,7 @@ use Drupal\user\UserInterface; * "id" = "id", * "bundle" = "type", * "label" = "update_timestamp", + * "langcode" = "langcode", * "uuid" = "uuid" * }, * links = { @@ -130,6 +131,10 @@ class ScheduledUpdate extends ContentEntityBase implements ScheduledUpdateInterf * {@inheritdoc} */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { + $fields['langcode'] = BaseFieldDefinition::create('language') + ->setLabel(t('Language code')) + ->setDescription(t('The language code for the Scheduled update entity.')); + $fields['id'] = BaseFieldDefinition::create('integer') ->setLabel(t('ID')) ->setDescription(t('The ID of the Scheduled update entity.')) diff --git a/src/Plugin/BaseUpdateRunner.php b/src/Plugin/BaseUpdateRunner.php index 5f6feb8..4afbe2d 100644 --- a/src/Plugin/BaseUpdateRunner.php +++ b/src/Plugin/BaseUpdateRunner.php @@ -227,7 +227,7 @@ abstract class BaseUpdateRunner extends PluginBase implements UpdateRunnerInterf $invalid_entity_ids = []; foreach (array_keys($entities_to_update) as $entity_id) { - $entity_to_update = $entities_to_update[$entity_id]; + $entity_to_update = $entities_to_update[$entity_id]->getTranslation($update->language()->getId()); $this->prepareEntityForUpdate($update, $queue_item, $entity_to_update); $this->switchUser($update, $entity_to_update); $violations = $entity_to_update->validate(); diff --git a/src/Plugin/UpdateRunner/EmbeddedUpdateRunner.php b/src/Plugin/UpdateRunner/EmbeddedUpdateRunner.php index 1f24e1e..0353207 100644 --- a/src/Plugin/UpdateRunner/EmbeddedUpdateRunner.php +++ b/src/Plugin/UpdateRunner/EmbeddedUpdateRunner.php @@ -39,30 +39,33 @@ class EmbeddedUpdateRunner extends BaseUpdateRunner implements EntityMonitorUpda $field_ids = $this->getReferencingFieldIds(); /** @var ContentEntityInterface $entity */ foreach ($entities as $entity) { - /** @var $entity_update_ids - all update ids for this entity for our fields. */ - $entity_update_ids = []; - /** @var $field_update_ids - update ids keyed by field_id. */ - $field_update_ids = []; - foreach ($field_ids as $field_id) { - // Store with field id. - $field_update_ids[$field_id] = $this->getEntityReferenceTargetIds($entity, $field_id); - // Add to all for entity. - $entity_update_ids += $field_update_ids[$field_id]; - } - // For all entity updates return only those ready to run. - $ready_update_ids = $this->getReadyUpdateIds($entity_update_ids); - // Loop through updates attached to fields. - foreach ($field_update_ids as $field_id => $update_ids) { - // For updates attached to field get only those ready to run. - $field_ready_update_ids = array_intersect($update_ids, $ready_update_ids); - foreach ($field_ready_update_ids as $field_ready_update_id) { - $updates[] = [ - 'update_id' => $field_ready_update_id, - // If this is revisionable entity use revision id as key for Runner Plugins that care about revisions. - 'entity_ids' => $entity->getRevisionId()? [$entity->getRevisionId() => $entity->id()]: [$entity->id()], - 'field_id' => $field_id, - 'entity_type' => $this->updateEntityType(), - ]; + foreach ($entity->getTranslationLanguages() as $langcode => $lang) { + $entity = $entity->getTranslation($langcode); + /** @var $entity_update_ids - all update ids for this entity for our fields. */ + $entity_update_ids = []; + /** @var $field_update_ids - update ids keyed by field_id. */ + $field_update_ids = []; + foreach ($field_ids as $field_id) { + // Store with field id. + $field_update_ids[$field_id] = $this->getEntityReferenceTargetIds($entity, $field_id); + // Add to all for entity. + $entity_update_ids += $field_update_ids[$field_id]; + } + // For all entity updates return only those ready to run. + $ready_update_ids = $this->getReadyUpdateIds($entity_update_ids); + // Loop through updates attached to fields. + foreach ($field_update_ids as $field_id => $update_ids) { + // For updates attached to field get only those ready to run. + $field_ready_update_ids = array_intersect($update_ids, $ready_update_ids); + foreach ($field_ready_update_ids as $field_ready_update_id) { + $updates[] = [ + 'update_id' => $field_ready_update_id, + // If this is revisionable entity use revision id as key for Runner Plugins that care about revisions. + 'entity_ids' => $entity->getRevisionId()? [$entity->getRevisionId() => $entity->id()]: [$entity->id()], + 'field_id' => $field_id, + 'entity_type' => $this->updateEntityType(), + ]; + } } } } diff --git a/src/Plugin/UpdateRunner/LatestRevisionUpdateRunner.php b/src/Plugin/UpdateRunner/LatestRevisionUpdateRunner.php index 9f8a908..93b2a4b 100644 --- a/src/Plugin/UpdateRunner/LatestRevisionUpdateRunner.php +++ b/src/Plugin/UpdateRunner/LatestRevisionUpdateRunner.php @@ -70,6 +70,8 @@ class LatestRevisionUpdateRunner extends EmbeddedUpdateRunner { // Check the latest revision was in the revisions sent to this function. if (in_array($latest_revision->getRevisionId(), $revision_ids)) { $revisions[$entity_id] = $latest_revision; + // @TODO: Test the index. + //$revisions[$latest_revision->getRevisionId()] = $latest_revision; } } return $revisions;