Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / path / src / Plugin / Field / FieldWidget / PathWidget.php
index ea69ca1bd06984d1d6a72fdd05c8e6bf283f61d1..13ab1f10767c28f1e4ca26a772f2af5f83ccd8c0 100644 (file)
@@ -5,7 +5,6 @@ namespace Drupal\path\Plugin\Field\FieldWidget;
 use Drupal\Core\Field\FieldItemListInterface;
 use Drupal\Core\Field\WidgetBase;
 use Drupal\Core\Form\FormStateInterface;
-use Drupal\Core\Language\LanguageInterface;
 use Symfony\Component\Validator\ConstraintViolationInterface;
 
 /**
@@ -26,23 +25,6 @@ class PathWidget extends WidgetBase {
    */
   public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
     $entity = $items->getEntity();
-    $path = [];
-    if (!$entity->isNew()) {
-      $conditions = ['source' => '/' . $entity->urlInfo()->getInternalPath()];
-      if ($items->getLangcode() != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
-        $conditions['langcode'] = $items->getLangcode();
-      }
-      $path = \Drupal::service('path.alias_storage')->load($conditions);
-      if ($path === FALSE) {
-        $path = [];
-      }
-    }
-    $path += [
-      'pid' => NULL,
-      'source' => !$entity->isNew() ? '/' . $entity->urlInfo()->getInternalPath() : NULL,
-      'alias' => '',
-      'langcode' => $items->getLangcode(),
-    ];
 
     $element += [
       '#element_validate' => [[get_class($this), 'validateFormElement']],
@@ -50,22 +32,22 @@ class PathWidget extends WidgetBase {
     $element['alias'] = [
       '#type' => 'textfield',
       '#title' => $element['#title'],
-      '#default_value' => $path['alias'],
+      '#default_value' => $items[$delta]->alias,
       '#required' => $element['#required'],
       '#maxlength' => 255,
       '#description' => $this->t('Specify an alternative path by which this data can be accessed. For example, type "/about" when writing an about page.'),
     ];
     $element['pid'] = [
       '#type' => 'value',
-      '#value' => $path['pid'],
+      '#value' => $items[$delta]->pid,
     ];
     $element['source'] = [
       '#type' => 'value',
-      '#value' => $path['source'],
-    ];
+      '#value' => !$entity->isNew() ? '/' . $entity->toUrl()->getInternalPath() : NULL,
+     ];
     $element['langcode'] = [
       '#type' => 'value',
-      '#value' => $path['langcode'],
+      '#value' => $items[$delta]->langcode,
     ];
     return $element;
   }