Commit caf7911d authored by Berdir's avatar Berdir Committed by Berdir
Browse files

Issue #2950701 by Berdir: Pathauto pattern is not applied on first node save

parent 489a6dd3
......@@ -18,6 +18,8 @@
* @ingroup pathauto
*/
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Form\FormStateInterface;
......@@ -82,6 +84,30 @@ function pathauto_help($route_name, RouteMatchInterface $route_match) {
}
}
/**
* Implements hook_entity_insert().
*/
function pathauto_entity_insert(EntityInterface $entity) {
\Drupal::service('pathauto.generator')->updateEntityAlias($entity, 'insert');
}
/**
* Implements hook_entity_update().
*/
function pathauto_entity_update(EntityInterface $entity) {
\Drupal::service('pathauto.generator')->updateEntityAlias($entity, 'update');
}
/**
* Implements hook_entity_update().
*/
function pathauto_entity_delete(EntityInterface $entity) {
if ($entity->hasLinkTemplate('canonical') && $entity instanceof ContentEntityInterface && $entity->hasField('path')) {
\Drupal::service('pathauto.alias_storage_helper')->deleteEntityPathAll($entity);
$entity->get('path')->first()->get('pathauto')->purge();
}
}
/**
* Implements hook_field_info_alter().
*/
......
......@@ -38,12 +38,4 @@ class PathautoFieldItemList extends PathFieldItemList {
}
}
/**
* @inheritDoc
*/
public function delete() {
\Drupal::service('pathauto.alias_storage_helper')->deleteEntityPathAll($this->getEntity());
$this->first()->get('pathauto')->purge();
}
}
......@@ -33,9 +33,6 @@ class PathautoItem extends PathItem {
if ($this->pathauto == PathautoState::SKIP) {
parent::postSave($update);
}
else {
\Drupal::service('pathauto.generator')->updateEntityAlias($this->getEntity(), $update ? 'update' : 'insert');
}
$this->get('pathauto')->persist();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment