Problem/Motivation

TypeError: Drupal\layout_paragraphs\LayoutParagraphsLayoutTempstoreRepository::getWithStorageKey(): Argument #1 ($key) must be of type string, null given, called in /var/www/clients/client54/web163/web/modules/layout_paragraphs/src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php on line 156 w Drupal\layout_paragraphs\LayoutParagraphsLayoutTempstoreRepository->getWithStorageKey() (linia 51 w /var/www/clients/client54/web163/web/modules/layout_paragraphs/src/LayoutParagraphsLayoutTempstoreRepository.php)

Steps to reproduce

Upgrade from 2.0.0-beta5 to 2.0.0-beta6

my temporaty work around

changed line 154
to

      if($layout_paragraphs_storage_key == NULL){
        $this->layoutParagraphsLayout = new LayoutParagraphsLayout($items, $this->getSettings());
        $this->tempstore->set($this->layoutParagraphsLayout);
        $layout_paragraphs_storage_key = $this->tempstore->getStorageKey($this->layoutParagraphsLayout);
      }else{
      $this->layoutParagraphsLayout = $this->tempstore->getWithStorageKey($layout_paragraphs_storage_key);
    }
CommentFileSizeAuthor
#3 null-storage-key-3258742-3.patch1.2 KBnuuou
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gryfini created an issue. See original summary.

avpaderno’s picture

Assigned: gryfini » Unassigned
nuuou’s picture

StatusFileSize
new1.2 KB

Moved the code from the start of this issue into a patch file.
No idea if this is the "proper" way to fix this issue or anything, but it did fix the issue for me on 2.0.0-beta6.

avpaderno’s picture

Version: 2.0.0-beta6 » 2.0.x-dev
Category: Support request » Bug report
Status: Active » Needs review
gryfini’s picture

this code look better
whole function formElement

  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    $input = $form_state->getUserInput();
    $parents = array_merge($form['#parents'], [$this->fieldDefinition->getName(), 'layout_paragraphs_storage_key']);
    $layout_paragraphs_storage_key = NestedArray::getValue($input, $parents);
    // If the form is being rendered for the first time, create a new Layout
    // Paragraphs Layout instance, save it to tempstore, and store the key.
    if (empty($input) || $layout_paragraphs_storage_key == NULL) {
      $this->layoutParagraphsLayout = new LayoutParagraphsLayout($items, $this->getSettings());
      $this->tempstore->set($this->layoutParagraphsLayout);
      $layout_paragraphs_storage_key = $this->tempstore->getStorageKey($this->layoutParagraphsLayout);
    }
    // On subsequent form renders, this loads the correct Layout Paragraphs
    // Layout from the tempstore using the storage key.
    else {
      $this->layoutParagraphsLayout = $this->tempstore->getWithStorageKey($layout_paragraphs_storage_key);
    }
    $element += [
      '#type' => 'fieldset',
      '#title' => $this->fieldDefinition->getLabel(),
      'layout_paragraphs_builder' => [
        '#type' => 'layout_paragraphs_builder',
        '#layout_paragraphs_layout' => $this->layoutParagraphsLayout,
      ],
      // Stores the Layout Paragraphs Layout storage key.
      'layout_paragraphs_storage_key' => [
        '#type' => 'hidden',
        '#default_value' => $layout_paragraphs_storage_key,
      ],
    ];
    if ($source = $form_state->get(['content_translation', 'source'])) {
      $element['layout_paragraphs_builder']['#source_langcode'] = $source->getId();
    }
    return $element;
  }

justin2pin made their first commit to this issue’s fork.

justin2pin’s picture

Status: Needs review » Fixed

Thanks all - this should be fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.