setComponent example

'label' => 'hidden',
      'settings' => [
        'format_type' => 'fallback',
        'separator' => 'UNTRANSLATED',
      ],
    ];
    EntityViewDisplay::create([
      'targetEntityType' => $this->field->getTargetEntityTypeId(),
      'bundle' => $this->field->getTargetBundle(),
      'mode' => 'default',
      'status' => TRUE,
    ])->setComponent($this->fieldStorage->getName()$display_options)
      ->save();
  }

  /** * Tests the translation of the range separator. */
  public function testSeparatorTranslation() {
    // Create an entity.     $entity = EntityTest::create([
      'name' => $this->randomString(),
      $this->fieldStorage->getName() => [
        
'auto_create' => TRUE,
    ];
    $this->createEntityReferenceField('node', 'article', $this->termFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    $field_storage = FieldStorageConfig::loadByName('node', $this->termFieldName);
    $field_storage->setTranslatable(FALSE);
    $field_storage->save();

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

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

}
$handler_settings = [
      'target_bundles' => [
        $this->vocabulary->id() => $this->vocabulary->id(),
      ],
      'auto_create' => TRUE,
    ];
    $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();
  }

  /** * Creates some terms and a node, then tests the tokens generated from them. */
$component = [
      'type' => 'comment_default',
      'settings' => ['view_mode' => $mode, 'pager_id' => 0],
    ];
    // Create a new 'entity_test' view display on host entity that uses the     // custom comment display in field formatter to show the field.     EntityViewDisplay::create([
      'targetEntityType' => 'entity_test',
      'bundle' => 'entity_test',
      'mode' => 'default',
    ])->setComponent($field_name$component)->setStatus(TRUE)->save();

    $host_display_id = 'entity_test.entity_test.default';
    $comment_display_id = "comment.comment.$mode";

    // Disable the "comment.comment.$mode" display.     EntityViewDisplay::load($comment_display_id)->setStatus(FALSE)->save();

    /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $host_display */
    $host_display = EntityViewDisplay::load($host_display_id);

    // Check that the field formatter has been disabled on host view display.
'entity_type' => 'node',
      'type' => $type,
    ])->save();
    FieldConfig::create([
      'field_name' => $this->fieldName,
      'entity_type' => 'node',
      'bundle' => $this->type,
    ])->save();

    \Drupal::service('entity_display.repository')
      ->getFormDisplay('node', $this->type)
      ->setComponent($this->fieldName)
      ->save();

    $this->adminPath = 'admin/structure/types/manage/' . $this->type . '/fields/node.' . $this->type . '.' . $this->fieldName . '/storage';
  }

  /** * Tests a string input for the 'allowed values' form element. * * @param string $input_string * The input string, in the pipe-linefeed format expected by the form * element. * @param array|string $result * Either an expected resulting array in * $field->getSetting('allowed_values'), or an expected error message. * @param string $message * Message to display. * * @internal */

    $field_storage->save();
    FieldConfig::create([
      'field_storage' => $field_storage,
      'bundle' => 'article',
      'label' => 'Telephone Number',
    ])->save();

    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');
    $display_repository->getFormDisplay('node', 'article')
      ->setComponent('field_telephone', [
        'type' => 'telephone_default',
        'settings' => [
          'placeholder' => '123-456-7890',
        ],
      ])
      ->save();

    $display_repository->getViewDisplay('node', 'article')
      ->setComponent('field_telephone', [
        'type' => 'telephone_link',
        'weight' => 1,
      ])
$field_storage->save();

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

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

  /** * Renders fields of a given entity with a given display. * * @param \Drupal\Core\Entity\FieldableEntityInterface $entity * The entity object with attached fields to render. * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display * The display to render the fields in. * * @return string * The rendered entity fields. */

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

    // Create an entity reference field and use the default 'CONTAINS' match     // operator.     $field_name = 'field_test';
    $this->createEntityReferenceField('node', 'page', $field_name$field_name, 'node', 'default', ['target_bundles' => ['page'], 'sort' => ['field' => 'title', 'direction' => 'DESC']]);
    $form_display = $display_repository->getFormDisplay('node', 'page');
    $form_display->setComponent($field_name[
      'type' => 'entity_reference_autocomplete',
      'settings' => [
        'match_operator' => 'CONTAINS',
      ],
    ]);
    // To satisfy config schema, the size setting must be an integer, not just     // a numeric value. See https://www.drupal.org/node/2885441.     $this->assertIsInt($form_display->getComponent($field_name)['settings']['size']);
    $form_display->save();
    $this->assertIsInt($form_display->getComponent($field_name)['settings']['size']);

    
'entity_type' => 'node',
      'type' => 'text',
    ])->save();
    FieldConfig::create([
      'field_name' => $this->fieldName,
      'entity_type' => 'node',
      'bundle' => 'page',
    ])->save();
    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');
    $display_repository->getViewDisplay('node', 'page')
      ->setComponent($this->fieldName)
      ->save();
    $display_repository->getFormDisplay('node', 'page')
      ->setComponent($this->fieldName)
      ->save();
  }

  /** * Tests administering fields when node access is restricted. */
  public function testNodeAccessAdministerField() {
    // Create a page node.
'enabled' => TRUE,
      'label' => $this->randomMachineName(),
    ])->save();
    EntityViewDisplay::create([
      'targetEntityType' => 'media',
      'bundle' => $media_type->id(),
      'mode' => 'foobar',
      'status' => TRUE,
    ])->removeComponent('thumbnail')
      ->removeComponent('created')
      ->removeComponent('uid')
      ->setComponent('field_media_image', [
        'label' => 'visually_hidden',
        'type' => 'image',
        'settings' => [
          'image_style' => 'medium',
          'image_link' => 'file',
        ],
        'third_party_settings' => [],
        'weight' => 1,
        'region' => 'content',
      ])
      ->save();
    
// Add the form mode and show the field with a constraint.     EntityFormMode::create([
      'id' => 'entity_test.layout_builder',
      'targetEntityType' => 'entity_test',
    ])->save();
    EntityFormDisplay::create([
      'targetEntityType' => 'entity_test',
      'bundle' => 'entity_test',
      'mode' => 'layout_builder',
      'status' => TRUE,
    ])
      ->setComponent('foo', [
        'type' => 'string_textfield',
      ])
      ->save();

    $this->drupalLogin($this->drupalCreateUser([
      'view test entity',
      'configure any layout',
      'configure all entity_test entity_test layout overrides',
    ]));

    EntityTest::create()->setName($this->randomMachineName())->save();
  }
// Use the `large` image style and do not link the image to anything.     // This will prevent the out-of-the-box configuration from outputting very     // large raw images. If the `large` image style has been deleted, do not     // set an image style.     $field_name = $this->getSourceFieldDefinition($type)->getName();
    $component = $display->getComponent($field_name);
    $component['settings']['image_link'] = '';
    $component['settings']['image_style'] = '';
    if ($this->entityTypeManager->getStorage('image_style')->load('large')) {
      $component['settings']['image_style'] = 'large';
    }
    $display->setComponent($field_name$component);
  }

}
$component = new Component();

        $component->setId((int) $data['__emotionLibraryComponent_id']);
        $component->setName($data['__emotionLibraryComponent_name']);
        $component->setType($data['__emotionLibraryComponent_x_type']);
        $component->setConvertFunction($data['__emotionLibraryComponent_convert_function']);
        $component->setDescription($data['__emotionLibraryComponent_description']);
        $component->setTemplate($data['__emotionLibraryComponent_template']);
        $component->setCssClass($data['__emotionLibraryComponent_cls']);
        $component->setPluginId($data['__emotionLibraryComponent_plugin_id'] !== null ? (int) $data['__emotionLibraryComponent_plugin_id'] : null);

        $element->setComponent($component);
    }

    private function assignConfig(Element $element, array $config = [])
    {
        $config = $this->assignConfigTranslation($config);

        $elementConfig = new ElementConfig($config);

        $element->setConfig($elementConfig);
    }

    

          // Enable auto-create.           'auto_create' => TRUE,
        ],
      ],
    ])->save();

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

    $display_repository->getViewDisplay('node', $referencing->id())
      ->setComponent('test_field')
      ->save();
    $display_repository->getFormDisplay('node', $referencing->id(), 'default')
      ->setComponent('test_field', [
        'type' => 'entity_reference_autocomplete',
      ])
      ->save();

    $account = $this->drupalCreateUser([
      'access content',
      "create $this->referencingType content",
    ]);
    
$this->files[] = $file;
  }

  /** * Tests the file_link field formatter. */
  public function testFormatterFileLink() {
    $entity_display = EntityViewDisplay::create([
      'targetEntityType' => 'file',
      'bundle' => 'file',
    ]);
    $entity_display->setComponent('filename', ['type' => 'file_link']);

    $build = $entity_display->buildMultiple($this->files)[0]['filename'][0];
    $this->assertEquals('file.png', $build['#title']);
    $this->assertEquals($this->fileUrlGenerator->generate('public://file.png')$build['#url']);
  }

  /** * Tests the file_link field formatter. */
  public function testFormatterFileUri() {
    $entity_display = EntityViewDisplay::create([
      
Home | Imprint | This part of the site doesn't use cookies.