getContextData example

throw new ContextException("The '$type' context is required and not present.");
      }
      return $default_value;
    }
    return $this->getTypedDataManager()->getCanonicalRepresentation($this->contextData);
  }

  /** * {@inheritdoc} */
  public function hasContextValue() {
    return $this->getTypedDataManager()->getCanonicalRepresentation($this->getContextData()) !== NULL;
  }

  /** * Sets the context value. * * @param mixed $value * The value of this context, matching the context definition. */
  protected function setContextValue($value) {
    // Add the value as a cacheable dependency only if implements the interface     // to prevent it from disabling caching with a max-age 0.

  public function isSatisfiedBy(ContextInterface $context) {
    $definition = $context->getContextDefinition();
    if (!$this->dataTypeMatches($context)) {
      return FALSE;
    }

    // Get the value for this context, either directly if possible or by     // introspecting the definition.     if ($context->hasContextValue()) {
      $values = [$context->getContextData()];
    }
    elseif ($definition instanceof self) {
      $values = $definition->getSampleValues();
    }
    else {
      $values = [];
    }

    $validator = $this->getTypedDataManager()->getValidator();
    foreach ($values as $value) {
      $constraints = array_values($this->getConstraintObjects());
      
$this->assertEquals('test', $context->getContextValue());
  }

  /** * @covers ::getContextData */
  public function testDefaultDataValue() {
    $this->setUpDefaultValue('test');

    $context = new Context($this->contextDefinition);
    $context->setTypedDataManager($this->typedDataManager);
    $this->assertEquals($this->typedData, $context->getContextData());
  }

  /** * @covers ::getContextData */
  public function testNullDataValue() {
    $this->setUpDefaultValue(NULL);

    $context = new Context($this->contextDefinition);
    $context->setTypedDataManager($this->typedDataManager);
    $this->assertEquals($this->typedData, $context->getContextData());
  }
$entity = $this->container->get('entity_type.manager')->getStorage($entity_type_id)->create($values);
    $entity->save();
    $class = new TestLayoutEntityHelperTrait();
    $result = $class->getSectionStorageForEntity($entity);
    $this->assertEquals($expected_context_keysarray_keys($result));
    if ($entity instanceof EntityViewDisplayInterface) {
      $this->assertEquals(EntityContext::fromEntity($entity)$result['display']);
    }
    elseif ($entity instanceof FieldableEntityInterface) {
      $this->assertEquals(EntityContext::fromEntity($entity)$result['entity']);
      $this->assertInstanceOf(Context::class$result['view_mode']);
      $this->assertEquals('full', $result['view_mode']->getContextData()->getValue());

      $expected_display = EntityViewDisplay::collectRenderDisplay($entity, 'full');
      $this->assertInstanceOf(EntityContext::class$result['display']);
      /** @var \Drupal\Core\Plugin\Context\EntityContext $display_entity_context */
      $display_entity_context = $result['display'];

      /** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $display_entity */
      $display_entity = $display_entity_context->getContextData()->getValue();
      $this->assertInstanceOf(LayoutBuilderEntityViewDisplay::class$display_entity);

      $this->assertEquals('full', $display_entity->getMode());
      
Home | Imprint | This part of the site doesn't use cookies.