getDisplayOptions example

/** * Tests the display configuration settings. * * @covers ::isDisplayConfigurable * @covers ::getDisplayOptions * @dataProvider factoryTypeProvider */
  public function testDisplayConfigurationSettings($factory_name) {
    $definition = $this->initializeFieldUsingFactory($factory_name);
    $this->assertEquals(FALSE, $definition->isDisplayConfigurable('foo'));
    $this->assertEquals(NULL, $definition->getDisplayOptions('foo'));

    $definition->setDisplayConfigurable('foo', TRUE);
    $this->assertEquals(TRUE, $definition->isDisplayConfigurable('foo'));
    $this->assertEquals(['region' => 'hidden']$definition->getDisplayOptions('foo'));

    $definition->setDisplayOptions('foo', ['foo' => 'bar']);
    $this->assertEquals(['foo' => 'bar']$definition->getDisplayOptions('foo'));
  }

  /** * Provides a Mock base field default value callback. * * @param \Drupal\Core\Entity\EntityInterface $entity * Entity interface. * @param \Drupal\Core\Field\FieldDefinitionInterface $definition * Field definition. * * @return string * Default value. */
/** * {@inheritdoc} */
  public function isDisplayConfigurable($context) {
    return $this->getBaseFieldDefinition()->isDisplayConfigurable($context);
  }

  /** * {@inheritdoc} */
  public function getDisplayOptions($display_context) {
    return $this->getBaseFieldDefinition()->getDisplayOptions($display_context);
  }

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

  /** * {@inheritdoc} */

  protected function checkDisplayOption($entity_type_id$field_id, BaseFieldDefinition $field_definition, DiscoveryInterface $plugin_manager$display_context) {
    $display_options = $field_definition->getDisplayOptions($display_context);
    if (!empty($display_options['type'])) {
      $plugin = $plugin_manager->getDefinition($display_options['type'], FALSE);
      $this->assertNotNull($pluginsprintf(
        'Plugin found for "%s" field %s display options of "%s" entity type.',
        $field_id,
        $display_context,
        $entity_type_id)
      );
    }
  }

  

        // Ensure extra fields have a 'region'.         if (isset($this->content[$name])) {
          $this->content[$name] += ['region' => $default_region];
        }
      }

      // Fill in defaults for fields.       $fields = $this->getFieldDefinitions();
      foreach ($fields as $name => $definition) {
        if (!$definition->isDisplayConfigurable($this->displayContext) || (!isset($this->content[$name]) && !isset($this->hidden[$name]))) {
          $options = $definition->getDisplayOptions($this->displayContext);

          if (!empty($options['region']) && $options['region'] === 'hidden') {
            $this->removeComponent($name);
          }
          elseif ($options) {
            $options += ['region' => $default_region];
            $this->setComponent($name$options);
          }
          // Note: (base) fields that do not specify display options are not           // tracked in the display at all, in order to avoid cluttering the           // configuration that gets saved back.
/** * Tests the Media "name" base field behavior. */
  public function testNameBaseField() {
    /** @var \Drupal\Core\Field\BaseFieldDefinition[] $field_definitions */
    $field_definitions = $this->container->get('entity_field.manager')
      ->getBaseFieldDefinitions('media');

    // Ensure media name is configurable on manage display.     $this->assertTrue($field_definitions['name']->isDisplayConfigurable('view'));
    // Ensure it is not visible by default.     $this->assertSame($field_definitions['name']->getDisplayOptions('view')['region' => 'hidden']);
  }

  /** * Tests permissions based on a media type have the correct permissions. */
  public function testPermissions() {
    $permissions = $this->container->get('user.permissions')->getPermissions();
    $name = "create {$this->testMediaType->id()} media";
    $this->assertArrayHasKey($name$permissions);
    $this->assertSame(['config' => [$this->testMediaType->getConfigDependencyName()]]$permissions[$name]['dependencies']);
  }

}
Home | Imprint | This part of the site doesn't use cookies.