public function UpdateHelper::legacyUpdateToRecipientPlugin in Workbench Email 8
Same name and namespace in other branches
- 2.x src/Update/UpdateHelper.php \Drupal\workbench_email\Update\UpdateHelper::legacyUpdateToRecipientPlugin()
Updates template entities in Drupal core < 8.6.
Parameters
array $sandbox: Stores information for batch updates.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException When the entity type is not found.
\Drupal\Component\Plugin\Exception\PluginNotFoundException When the entity type is not found.
\Drupal\Core\Entity\EntityStorageException If an error occurs during update.
See also
workbench_email_post_update_move_to_recipient_plugins()
File
- src/
Update/ UpdateHelper.php, line 102
Class
- UpdateHelper
- Defines a class for update helpers.
Namespace
Drupal\workbench_email\UpdateCode
public function legacyUpdateToRecipientPlugin(array &$sandbox) {
$storage = $this->entityTypeManager
->getStorage('workbench_email_template');
$sandbox_key = 'config_entity_updater:workbench_email_template';
if (!isset($sandbox[$sandbox_key])) {
$sandbox[$sandbox_key]['entities'] = $storage
->getQuery()
->accessCheck(FALSE)
->execute();
$sandbox[$sandbox_key]['count'] = count($sandbox[$sandbox_key]['entities']);
}
/** @var \Drupal\workbench_email\TemplateInterface $template */
$entities = $storage
->loadMultiple(array_splice($sandbox[$sandbox_key]['entities'], 0, 50));
foreach ($entities as $template) {
if (self::updateToRecipientPlugin($template)) {
$template
->trustData();
$template
->save();
}
}
$sandbox['#finished'] = empty($sandbox[$sandbox_key]['entities']) ? 1 : ($sandbox[$sandbox_key]['count'] - count($sandbox[$sandbox_key]['entities'])) / $sandbox[$sandbox_key]['count'];
}