getViewDisplay example

// Test theme function for responsive image, but using the test formatter.     $display_options = [
      'type' => 'responsive_image_test',
      'settings' => [
        'image_link' => 'file',
        'responsive_image_style' => 'style_one',
      ],
    ];
    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');
    $display = $display_repository->getViewDisplay('node', 'article');
    $display->setComponent($field_name$display_options)
      ->save();

    $this->drupalGet('node/' . $nid);

    // Use the responsive image formatter linked to file formatter.     $display_options = [
      'type' => 'responsive_image',
      'settings' => [
        'image_link' => 'file',
        'responsive_image_style' => 'style_one',
      ],

      $field->save();

      // Assign widget settings for the default form mode.       $this->entityDisplayRepository->getFormDisplay('comment', $comment_type_id)
        ->setComponent('comment_body', [
          'type' => 'text_textarea',
        ])
        ->save();

      // Assign display settings for the default view mode.       $this->entityDisplayRepository->getViewDisplay('comment', $comment_type_id)
        ->setComponent('comment_body', [
          'label' => 'hidden',
          'type' => 'text_default',
          'weight' => 0,
        ])
        ->save();
    }
  }

  /** * {@inheritdoc} */
'test_formatter_setting' => $this->randomMachineName(),
        ],
      ],
    ];

    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');

    FieldStorageConfig::create($field_storage)->save();
    FieldConfig::create($field)->save();
    // Create a display for the default view mode.     $display_repository->getViewDisplay($field['entity_type']$field['bundle'])
      ->setComponent($this->fieldName, $this->displayOptions['default'])
      ->save();
    // Create a display for the teaser view mode.     EntityViewMode::create(['id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'])->save();
    $display_repository->getViewDisplay($field['entity_type']$field['bundle'], 'teaser')
      ->setComponent($this->fieldName, $this->displayOptions['teaser'])
      ->save();

    // Create an entity with values.     $this->values = $this->_generateTestFieldValues($this->cardinality);
    $this->entity = EntityTest::create();
    
'entity_reference_comment',
      'Entity Reference Comment',
      'comment',
      'default',
      ['target_bundles' => ['comment']]
    );
    \Drupal::service('entity_display.repository')
      ->getFormDisplay('node', 'article')
      ->setComponent('entity_reference_comment', ['type' => 'options_select'])
      ->save();
    \Drupal::service('entity_display.repository')
      ->getViewDisplay('node', 'article')
      ->setComponent('entity_reference_comment', ['type' => 'entity_reference_label'])
      ->save();

    $administratorUser = $this->drupalCreateUser([
      'skip comment approval',
      'post comments',
      'access comments',
      'access content',
      'administer nodes',
      'administer comments',
      'bypass node access',
    ]);
'type' => 'boolean',
    ]);
    $field_storage->save();

    $instance = FieldConfig::create([
      'field_storage' => $field_storage,
      'bundle' => $this->bundle,
      'label' => $this->randomMachineName(),
    ]);
    $instance->save();

    $display = \Drupal::service('entity_display.repository')->getViewDisplay('node', $this->bundle)
      ->setComponent($this->fieldName, [
        'type' => 'boolean',
        'settings' => [],
      ]);
    $display->save();
  }

  /** * Tests the formatter settings page for the Boolean formatter. */
  public function testBooleanFormatterSettings() {
    
->save();
    FieldConfig::create([
      'entity_type' => $this->entityType,
      'field_name' => $this->fieldName,
      'bundle' => $this->bundle,
      'settings' => [
        'file_extensions' => 'jpg',
      ],
    ])->save();

    $this->display = \Drupal::service('entity_display.repository')
      ->getViewDisplay($this->entityType, $this->bundle)
      ->setComponent($this->fieldName, [
        'type' => 'image',
        'label' => 'hidden',
      ]);
    $this->display->save();
  }

  /** * Tests the cache tags from image formatters. */
  public function testImageFormatterCacheTags() {
    
'bundle' => $node_type->id(),
      'label' => 'Related media',
      'settings' => [
        'handler_settings' => [
          'target_bundles' => [
            'image' => 'image',
          ],
        ],
      ],
    ])->save();

    \Drupal::service('entity_display.repository')->getViewDisplay('node', $node_type->id())
      ->setComponent('field_related_media', [
        'type' => 'entity_reference_entity_view',
        'label' => 'above',
        'settings' => [
          'view_mode' => 'full',
        ],
      ])->save();

    $node = Node::create([
      'title' => 'Host node',
      'type' => $node_type->id(),
      
$field_config = FieldConfig::create([
      'entity_type' => $entity_type,
      'field_name' => $field_name,
      'bundle' => $bundle,
      'settings' => [
        'file_extensions' => trim($file_extensions),
      ],
    ]);
    $field_config->save();

    $this->container->get('entity_display.repository')
      ->getViewDisplay('entity_test', 'entity_test', 'full')
      ->setComponent($field_name[
        'type' => $formatter,
        'settings' => $formatter_settings,
      ])
      ->save();

    return $field_config;
  }

  /** * Data provider for testRender. * * @return array * An array of data arrays. * The data array contains: * - The number of expected HTML tags. * - An array of settings for the field formatter. */

    ]);
    $field2->save();

    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');

    $widget_settings = $display_repository->getFormDisplay('node', $field->getTargetBundle())->getComponent($field_name);
    $display_repository->getFormDisplay('node', 'page')
      ->setComponent($field_name$widget_settings)
      ->save();
    $display_repository->getViewDisplay('node', 'page')
      ->setComponent($field_name)
      ->save();

    // Confirm the defaults are present on the article field storage settings     // form.     $field_id = $field->id();
    $this->drupalGet("admin/structure/types/manage/article/fields/$field_id/storage");
    $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field_storage']->id());
    // Confirm the defaults are present on the article field edit form.     $this->drupalGet("admin/structure/types/manage/article/fields/$field_id");
    $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field']->id());

    

    $this->createEntityReferenceField('node', 'article', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    $this->field = FieldConfig::loadByName('node', 'article', $field_name);

    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');
    $display_repository->getFormDisplay('node', 'article')
      ->setComponent($field_name[
        'type' => 'options_select',
      ])
      ->save();
    $display_repository->getViewDisplay('node', 'article')
      ->setComponent($field_name[
        'type' => 'entity_reference_label',
      ])
      ->save();
  }

  /** * The "parent" field must restrict references to the same vocabulary. */
  public function testParentHandlerSettings() {
    $vocabulary_fields = \Drupal::service('entity_field.manager')->getFieldDefinitions('taxonomy_term', $this->vocabulary->id());
    

  protected function assertPageCounts(string $path, array $counts, string $message): void {
    // Disable read more links.     \Drupal::service('entity_display.repository')
      ->getViewDisplay('node', 'page', 'teaser')
      ->removeComponent('links')
      ->save();

    // Get the text of the page.     $this->drupalGet($path);
    $text = $this->getTextContent();

    // Check the counts. Note that the title and body are both shown on the     // page, and they are the same. So the title/body string should appear on     // the page twice as many times as the input count.     foreach ($counts as $langcode => $count) {
      
protected $defaultTheme = 'stark';

  /** * Tests the language extra field display. */
  public function testViewLanguage() {
    // Add Spanish language.     ConfigurableLanguage::createFromLangcode('es')->save();

    // Set language field visible.     \Drupal::service('entity_display.repository')
      ->getViewDisplay('node', 'page', 'full')
      ->setComponent('langcode')
      ->save();

    // Create a node in Spanish.     $node = $this->drupalCreateNode(['langcode' => 'es']);

    $this->drupalGet($node->toUrl());
    $this->assertSession()->pageTextContains('Spanish');
  }

}
    $content = $this->drupalBuildEntityView($node, 'teaser');
    $this->assertLessThan(600, strlen($content['body'][0]['#markup']));
    $this->setRawContent($renderer->renderRoot($content));
    // The string 'What is a Drupalism?' is between the 200th and 600th     // characters of the node body, so it should be included if the summary is     // 600 characters long.     $expected = 'What is a Drupalism?';
    $this->assertRaw($expected);

    // Change the teaser length for "Basic page" content type.     $display = \Drupal::service('entity_display.repository')
      ->getViewDisplay('node', $node->getType(), 'teaser');
    $display_options = $display->getComponent('body');
    $display_options['settings']['trim_length'] = 200;
    $display->setComponent('body', $display_options)
      ->save();

    // Render the node as a teaser again and check that the summary is now only     // 200 characters in length and so does not include 'What is a Drupalism?'.     $content = $this->drupalBuildEntityView($node, 'teaser');
    $this->assertLessThan(200, strlen($content['body'][0]['#markup']));
    $this->setRawContent($renderer->renderRoot($content));
    $this->assertText($node->label());
    

    ]);
    $field_storage->save();
    FieldConfig::create([
      'field_storage' => $field_storage,
      'bundle' => $this->entityTypeId,
      'label' => 'Reference',
      'translatable' => FALSE,
    ])->save();

    $this->container->get('entity_display.repository')
      ->getViewDisplay($this->entityTypeId, $this->entityTypeId, 'default')
      ->setComponent('field_reference', [
        'type' => 'entity_reference_entity_view',
      ])
      ->save();

    $this->setupEntity();

    // Create a second entity that references the first to test how the     // translation can be viewed through an entity reference field.     $this->referencingEntity = EntityTestMulRevPub::create([
      'name' => 'referencing',
      

    $this->createEntityReferenceField('node', 'article', $this->fieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);

    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');

    $display_repository->getFormDisplay('node', 'article')
      ->setComponent($this->fieldName, [
        'type' => 'options_select',
      ])
      ->save();
    $display_repository->getViewDisplay('node', 'article')
      ->setComponent($this->fieldName, [
        'type' => 'entity_reference_label',
      ])
      ->save();
  }

  /** * Tests that terms added to nodes are displayed in core RSS feed. * * Create a node and assert that taxonomy terms appear in rss.xml. */
  
Home | Imprint | This part of the site doesn't use cookies.