use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\ContextAwarePluginBase;
+use Drupal\Core\Messenger\MessengerTrait;
use Drupal\pathauto\AliasTypeBatchUpdateInterface;
use Drupal\pathauto\AliasTypeInterface;
use Drupal\pathauto\PathautoState;
*/
class EntityAliasTypeBase extends ContextAwarePluginBase implements AliasTypeInterface, AliasTypeBatchUpdateInterface, ContainerFactoryPluginInterface {
+ use MessengerTrait;
+
/**
* The module handler service.
*
case 'create':
$query->isNull('ua.source');
break;
+
case 'update':
$query->isNotNull('ua.source');
break;
+
case 'all':
// Nothing to do. We want all paths.
break;
+
default:
// Unknown action. Abort!
return;
$updates = $this->bulkUpdate($ids);
$context['sandbox']['count'] += count($ids);
- $context['sandbox']['current'] = max($ids);
+ $context['sandbox']['current'] = !empty($ids) ? max($ids) : 0;
$context['results']['updates'] += $updates;
$context['message'] = $this->t('Updated alias for %label @id.', array('%label' => $entity_type->getLabel(), '@id' => end($ids)));
* An optional array of additional options.
*
* @return int
- * The number of updated URL aliases.
+ * The number of updated URL aliases.
*/
protected function bulkUpdate(array $ids, array $options = array()) {
$options += array('message' => FALSE);
}
if (!empty($options['message'])) {
- drupal_set_message(\Drupal::translation()->formatPlural(count($ids), 'Updated 1 %label URL alias.', 'Updated @count %label URL aliases.'), array('%label' => $this->getLabel()));
+ $this->messenger->addMessage($this->translationManager
+ ->formatPlural(count($ids), 'Updated 1 %label URL alias.', 'Updated @count %label URL aliases.'), [
+ '%label' => $this->getLabel(),
+ ]);
}
return $updates;
return $this;
}
-
}