Version 1
[yaffs-website] / web / core / modules / path / src / Plugin / Field / FieldType / PathFieldItemList.php
1 <?php
2
3 namespace Drupal\path\Plugin\Field\FieldType;
4
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Field\FieldItemList;
7 use Drupal\Core\Session\AccountInterface;
8
9 /**
10  * Represents a configurable entity path field.
11  */
12 class PathFieldItemList extends FieldItemList {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function defaultAccess($operation = 'view', AccountInterface $account = NULL) {
18     if ($operation == 'view') {
19       return AccessResult::allowed();
20     }
21     return AccessResult::allowedIfHasPermissions($account, ['create url aliases', 'administer url aliases'], 'OR')->cachePerPermissions();
22   }
23
24   /**
25    * {@inheritdoc}
26    */
27   public function delete() {
28     // Delete all aliases associated with this entity in the current language.
29     $entity = $this->getEntity();
30     $conditions = [
31       'source' => '/' . $entity->toUrl()->getInternalPath(),
32       'langcode' => $entity->language()->getId(),
33     ];
34     \Drupal::service('path.alias_storage')->delete($conditions);
35   }
36
37 }