a7799930edbb061faa86ead9295a7adc9e92ff86
[yaffs-website] / web / modules / contrib / pathauto / src / PathautoItem.php
1 <?php
2
3 namespace Drupal\pathauto;
4
5 use Drupal\Core\Field\FieldStorageDefinitionInterface;
6 use Drupal\Core\TypedData\DataDefinition;
7 use Drupal\path\Plugin\Field\FieldType\PathItem;
8
9 /**
10  * Extends the default PathItem implementation to generate aliases.
11  */
12 class PathautoItem extends PathItem {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
18     $properties = parent::propertyDefinitions($field_definition);
19     $properties['pathauto'] = DataDefinition::create('integer')
20       ->setLabel(t('Pathauto state'))
21       ->setDescription(t('Whether an automated alias should be created or not.'))
22       ->setComputed(TRUE)
23       ->setClass('\Drupal\pathauto\PathautoState');
24     return $properties;
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function postSave($update) {
31     // Only allow the parent implementation to act if pathauto will not create
32     // an alias.
33     if ($this->pathauto == PathautoState::SKIP) {
34       parent::postSave($update);
35     }
36     $this->get('pathauto')->persist();
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function isEmpty() {
43     // Make sure that the pathauto state flag does not get lost if just that is
44     // changed.
45     return !$this->alias && !$this->get('pathauto')->hasValue();
46   }
47
48 }