示例#1
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('local_tasks_block');
     $this->drupalPlaceBlock('local_actions_block');
     $this->drupalPlaceBlock('page_title_block');
     $this->type = $this->createProfileType('test', 'Test profile', TRUE);
     $id = $this->type->id();
     $field_storage = FieldStorageConfig::create(['field_name' => 'profile_fullname', 'entity_type' => 'profile', 'type' => 'text']);
     $field_storage->save();
     $this->field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->type->id(), 'label' => 'Full name']);
     $this->field->save();
     // Configure the default display.
     $this->display = EntityViewDisplay::load("profile.{$this->type->id()}.default");
     if (!$this->display) {
         $this->display = EntityViewDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]);
         $this->display->save();
     }
     $this->display->setComponent($this->field->getName(), ['type' => 'string'])->save();
     // Configure rhe default form.
     $this->form = EntityFormDisplay::load("profile.{$this->type->id()}.default");
     if (!$this->form) {
         $this->form = EntityFormDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]);
         $this->form->save();
     }
     $this->form->setComponent($this->field->getName(), ['type' => 'string_textfield'])->save();
     $this->checkPermissions(['administer profile types', "view own {$id} profile", "view any {$id} profile", "add own {$id} profile", "add any {$id} profile", "edit own {$id} profile", "edit any {$id} profile", "delete own {$id} profile", "delete any {$id} profile"]);
     user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['access user profiles']);
     $this->adminUser = $this->drupalCreateUser(['administer profile types', "view any {$id} profile", "add any {$id} profile", "edit any {$id} profile", "delete any {$id} profile"]);
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalCreateContentType(['type' => 'article']);
     $this->adminUser = $this->drupalCreateUser(['create article content', 'edit own article content', 'administer content types', 'administer node fields']);
     $this->drupalLogin($this->adminUser);
     // Add the address field to the article content type.
     $field_storage = FieldStorageConfig::create(['field_name' => 'field_address', 'entity_type' => 'node', 'type' => 'address']);
     $field_storage->save();
     $this->field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => 'article', 'label' => 'Address']);
     $this->field->save();
     // Set article's form display.
     $this->formDisplay = EntityFormDisplay::load('node.article.default');
     if (!$this->formDisplay) {
         $this->formDisplay = EntityFormDisplay::create(['targetEntityType' => 'node', 'bundle' => 'article', 'mode' => 'default', 'status' => TRUE])->save();
     }
     $this->formDisplay->setComponent($this->field->getName(), ['type' => 'address_default', 'settings' => ['default_country' => 'US']])->save();
     $this->nodeAddUrl = 'node/add/article';
     $this->fieldConfigUrl = 'admin/structure/types/manage/article/fields/node.article.' . $this->field->getName();
     $this->countryRepository = \Drupal::service('address.country_repository');
     $this->subdivisionRepository = \Drupal::service('address.subdivision_repository');
     $this->addressFormatRepository = \Drupal::service('address.address_format_repository');
 }
示例#3
0
/**
 * Alter the settings used for displaying an entity form.
 *
 * @param \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display
 *   The entity_form_display object that will be used to display the entity form
 *   components.
 * @param array $context
 *   An associative array containing:
 *   - entity_type: The entity type, e.g., 'node' or 'user'.
 *   - bundle: The bundle, e.g., 'page' or 'article'.
 *   - form_mode: The form mode, e.g. 'default', 'profile', 'register'...
 *
 * @ingroup entity_crud
 */
function hook_entity_form_display_alter(\Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display, array $context)
{
    // Hide the 'user_picture' field from the register form.
    if ($context['entity_type'] == 'user' && $context['form_mode'] == 'register') {
        $form_display->setComponent('user_picture', array('type' => 'hidden'));
    }
}
 /**
  * Set component settings for the form.
  *
  * @param string $type
  *   The component to change settings for.
  * @param array $settings
  *   The settings to use.
  */
 protected function setFormComponentSettings($type, $settings = [])
 {
     $this->entityFormDisplay->setComponent($this->fieldName, ['type' => $type, 'settings' => $settings])->save();
 }