getTemporaryValue example


  use ContextAwarePluginTrait;
  use ContextAwarePluginAssignmentTrait;

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = $this->traitBuildConfigurationForm($form$form_state);

    // Add context mapping UI form elements.     $contexts = $form_state->getTemporaryValue('gathered_contexts') ?: [];
    $form['context_mapping'] = $this->addContextAssignmentElement($this$contexts);

    return $form;
  }

}
    $this->updateChangedTime($this->entity);
  }

  /** * {@inheritdoc} */
  public function buildEntity(array $form, FormStateInterface $form_state) {
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = parent::buildEntity($form$form_state);

    // Mark the entity as requiring validation.     $entity->setValidationRequired(!$form_state->getTemporaryValue('entity_validated'));

    // Save as a new revision if requested to do so.     if ($this->showRevisionUi() && !$form_state->isValueEmpty('revision')) {
      $entity->setNewRevision();
      if ($entity instanceof RevisionLogInterface) {
        // If a new revision is created, save the current user as         // revision author.         $entity->setRevisionUserId($this->currentUser()->id());
        $entity->setRevisionCreationTime($this->time->getRequestTime());
      }
    }

    

  public function DgetTemporaryValue($key);

  /** * Sets an arbitrary value in temporary storage. * * @param string|array $key * Properties are often stored as multi-dimensional associative arrays. If * $key is a string, it will use $temporary[$key] = $value. If $key is an * array, each element of the array will be used as a nested key. If * $key = ['foo', 'bar'] it will use $temporary['foo']['bar'] = $value. * @param mixed $value * The value to set. * * @return $this */
public function testGetTemporaryValue($key$value = NULL) {
    // Use PHPUnit for mocking, because Prophecy cannot mock methods that return     // by reference. See \Prophecy\Doubler\Generator\Node::getCode().     $decorated_form_state = $this->createMock(FormStateInterface::class);
    $decorated_form_state->expects($this->once())
      ->method('getTemporaryValue')
      ->with($key)
      ->willReturn($value);

    $this->formStateDecoratorBase = new NonAbstractFormStateDecoratorBase($decorated_form_state);

    $this->assertSame($value$this->formStateDecoratorBase->getTemporaryValue($key));
  }

  /** * Provides data to self::testGetTemporaryValue(). */
  public function providerGetTemporaryValue() {
    return [
      [TRUE, 'FOO', 'BAR'],
      [TRUE, 'FOO', NULL],
    ];
  }

  
/** * {@inheritdoc} */
  public function getTemporary() {
    return $this->decoratedFormState->getTemporary();
  }

  /** * {@inheritdoc} */
  public function DgetTemporaryValue($key) {
    return $this->decoratedFormState->getTemporaryValue($key);
  }

  /** * {@inheritdoc} */
  public function setTemporaryValue($key$value) {
    $this->decoratedFormState->setTemporaryValue($key$value);

    return $this;
  }

  
// @todo Remove when https://www.drupal.org/project/drupal/issues/2948549 is closed.     $form_state->setTemporaryValue('block_form_parents', $block_form['#parents']);
  }

  /** * {@inheritdoc} */
  public function blockSubmit($form, FormStateInterface $form_state) {
    $this->configuration['view_mode'] = $form_state->getValue('view_mode');

    // @todo Remove when https://www.drupal.org/project/drupal/issues/2948549 is closed.     $block_form = NestedArray::getValue($form$form_state->getTemporaryValue('block_form_parents'));
    /** @var \Drupal\block_content\BlockContentInterface $block */
    $block = $block_form['#block'];
    $form_display = EntityFormDisplay::collectRenderDisplay($block, 'edit');
    $complete_form_state = $form_state instanceof SubformStateInterface ? $form_state->getCompleteFormState() : $form_state;
    $form_display->extractFormValues($block$block_form$complete_form_state);
    $block->setInfo($this->configuration['label']);
    $this->configuration['block_serialized'] = serialize($block);
  }

  /** * {@inheritdoc} */


  /** * @covers ::getTemporaryValue * @covers ::hasTemporaryValue * @covers ::setTemporaryValue */
  public function testTemporaryValue() {
    $form_state = new FormState();
    $this->assertFalse($form_state->hasTemporaryValue('rainbow_sparkles'));
    $form_state->setTemporaryValue('rainbow_sparkles', 'yes please');
    $this->assertSame($form_state->getTemporaryValue('rainbow_sparkles'), 'yes please');
    $this->assertTrue($form_state->hasTemporaryValue('rainbow_sparkles'), TRUE);
    $form_state->setTemporaryValue(['rainbow_sparkles', 'magic_ponies'], 'yes please');
    $this->assertSame($form_state->getTemporaryValue(['rainbow_sparkles', 'magic_ponies']), 'yes please');
    $this->assertTrue($form_state->hasTemporaryValue(['rainbow_sparkles', 'magic_ponies']), TRUE);
  }

  /** * @covers ::getCleanValueKeys */
  public function testGetCleanValueKeys() {
    $form_state = new FormState();
    
public function isNegated() {
    return !empty($this->configuration['negate']);
  }

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    if ($form_state instanceof SubformStateInterface) {
      $form_state = $form_state->getCompleteFormState();
    }
    $contexts = $form_state->getTemporaryValue('gathered_contexts') ?: [];
    $form['context_mapping'] = $this->addContextAssignmentElement($this$contexts);
    $form['negate'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Negate the condition'),
      '#default_value' => $this->configuration['negate'],
    ];
    return $form;
  }

  /** * {@inheritdoc} */


  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Administrative label'),
      '#default_value' => $this->configuration['label'],
    ];
    $contexts = $form_state->getTemporaryValue('gathered_contexts') ?: [];
    $form['context_mapping'] = $this->addContextAssignmentElement($this$contexts);
    return $form;
  }

  /** * {@inheritdoc} */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  }

  /** * {@inheritdoc} */
/** * {@inheritdoc} */
  public function getTemporary() {
    return $this->temporary;
  }

  /** * {@inheritdoc} */
  public function DgetTemporaryValue($key) {
    $value = &NestedArray::getValue($this->temporary, (array) $key);
    return $value;
  }

  /** * {@inheritdoc} */
  public function setTemporaryValue($key$value) {
    NestedArray::setValue($this->temporary, (array) $key$value, TRUE);
    return $this;
  }

  
'#title' => $this->t('Visibility'),
      '#parents' => ['visibility_tabs'],
      '#attached' => [
        'library' => [
          'block/drupal.block',
        ],
      ],
    ];
    // @todo Allow list of conditions to be configured in     // https://www.drupal.org/node/2284687.     $visibility = $this->entity->getVisibility();
    $definitions = $this->manager->getFilteredDefinitions('block_ui', $form_state->getTemporaryValue('gathered_contexts')['block' => $this->entity]);
    foreach ($definitions as $condition_id => $definition) {
      // Don't display the current theme condition.       if ($condition_id == 'current_theme') {
        continue;
      }
      // Don't display the language condition until we have multiple languages.       if ($condition_id == 'language' && !$this->language->isMultilingual()) {
        continue;
      }

      /** @var \Drupal\Core\Condition\ConditionInterface $condition */
      
Home | Imprint | This part of the site doesn't use cookies.