function PathFieldItemList::computeValue
Same name in other branches
- 9 core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php \Drupal\path\Plugin\Field\FieldType\PathFieldItemList::computeValue()
- 8.9.x core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php \Drupal\path\Plugin\Field\FieldType\PathFieldItemList::computeValue()
- 11.x core/modules/path/src/Plugin/Field/FieldType/PathFieldItemList.php \Drupal\path\Plugin\Field\FieldType\PathFieldItemList::computeValue()
Overrides ComputedItemListTrait::computeValue
File
-
core/
modules/ path/ src/ Plugin/ Field/ FieldType/ PathFieldItemList.php, line 20
Class
- PathFieldItemList
- Represents a configurable entity path field.
Namespace
Drupal\path\Plugin\Field\FieldTypeCode
protected function computeValue() {
// Default the langcode to the current language if this is a new entity or
// there is no alias for an existent entity.
// @todo Set the langcode to not specified for untranslatable fields
// in https://www.drupal.org/node/2689459.
$value = [
'langcode' => $this->getLangcode(),
];
$entity = $this->getEntity();
if (!$entity->isNew()) {
/** @var \Drupal\path_alias\AliasRepositoryInterface $path_alias_repository */
$path_alias_repository = \Drupal::service('path_alias.repository');
if ($path_alias = $path_alias_repository->lookupBySystemPath('/' . $entity->toUrl()
->getInternalPath(), $this->getLangcode())) {
$value = [
'alias' => $path_alias['alias'],
'pid' => $path_alias['id'],
'langcode' => $path_alias['langcode'],
];
}
}
$this->list[0] = $this->createItem(0, $value);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.