Beispiel #1
0
 /**
  * Ensures that entity types with bundles do not break following entity types.
  */
 public function testFieldUIRoutes()
 {
     $this->drupalGet('entity_test_no_id/structure/entity_test/fields');
     $this->assertText('No fields are present yet.');
     $this->drupalGet('admin/config/people/accounts/fields');
     $this->assertTitle('Manage fields | Drupal');
     $this->assertLocalTasks();
     // Test manage display tabs and titles.
     $this->drupalGet('admin/config/people/accounts/display/compact');
     $this->assertResponse(403);
     $this->drupalGet('admin/config/people/accounts/display');
     $this->assertTitle('Manage display | Drupal');
     $this->assertLocalTasks();
     $edit = array('display_modes_custom[compact]' => TRUE);
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->drupalGet('admin/config/people/accounts/display/compact');
     $this->assertTitle('Manage display | Drupal');
     $this->assertLocalTasks();
     // Test manage form display tabs and titles.
     $this->drupalGet('admin/config/people/accounts/form-display/register');
     $this->assertResponse(403);
     $this->drupalGet('admin/config/people/accounts/form-display');
     $this->assertTitle('Manage form display | Drupal');
     $this->assertLocalTasks();
     $edit = array('display_modes_custom[register]' => TRUE);
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->assertResponse(200);
     $this->drupalGet('admin/config/people/accounts/form-display/register');
     $this->assertTitle('Manage form display | Drupal');
     $this->assertLocalTasks();
     $this->assert(count($this->xpath('//ul/li[1]/a[contains(text(), :text)]', array(':text' => 'Default'))) == 1, 'Default secondary tab is in first position.');
     // Create new view mode and verify it's available on the Manage Display
     // screen after enabling it.
     EntityViewMode::create(array('id' => 'user.test', 'label' => 'Test', 'targetEntityType' => 'user'))->save();
     $this->container->get('router.builder')->rebuildIfNeeded();
     $edit = array('display_modes_custom[test]' => TRUE);
     $this->drupalPostForm('admin/config/people/accounts/display', $edit, t('Save'));
     $this->assertLink('Test');
     // Create new form mode and verify it's available on the Manage Form
     // Display screen after enabling it.
     EntityFormMode::create(array('id' => 'user.test', 'label' => 'Test', 'targetEntityType' => 'user'))->save();
     $this->container->get('router.builder')->rebuildIfNeeded();
     $edit = array('display_modes_custom[test]' => TRUE);
     $this->drupalPostForm('admin/config/people/accounts/form-display', $edit, t('Save'));
     $this->assertLink('Test');
 }
Beispiel #2
0
 /**
  * Tests deleting field.
  */
 public function testDeleteField()
 {
     $field_name = 'test_field';
     // Create a field storage and a field.
     $field_storage = entity_create('field_storage_config', array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'test_field'));
     $field_storage->save();
     $field = entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => 'entity_test'));
     $field->save();
     // Create default and compact entity display.
     EntityFormMode::create(array('id' => 'entity_test.compact', 'targetEntityType' => 'entity_test'))->save();
     entity_create('entity_form_display', array('targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'default'))->setComponent($field_name)->save();
     entity_create('entity_form_display', array('targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'compact'))->setComponent($field_name)->save();
     // Check the component exists.
     $display = entity_get_form_display('entity_test', 'entity_test', 'default');
     $this->assertTrue($display->getComponent($field_name));
     $display = entity_get_form_display('entity_test', 'entity_test', 'compact');
     $this->assertTrue($display->getComponent($field_name));
     // Delete the field.
     $field->delete();
     // Check that the component has been removed from the entity displays.
     $display = entity_get_form_display('entity_test', 'entity_test', 'default');
     $this->assertFalse($display->getComponent($field_name));
     $display = entity_get_form_display('entity_test', 'entity_test', 'compact');
     $this->assertFalse($display->getComponent($field_name));
 }
 /**
  * {@inheritdoc}
  */
 public function postSave(EntityStorageInterface $storage, $update = TRUE)
 {
     parent::postSave($storage, $update);
     // Create mode for the entity type.
     $mode_id = $this->entity_type . '.rng_event';
     if (!EntityFormMode::load($mode_id)) {
         EntityFormMode::create(['id' => $mode_id, 'targetEntityType' => $this->entity_type, 'label' => 'Event Settings', 'status' => TRUE])->save();
     }
     if (!$update) {
         module_load_include('inc', 'rng', 'rng.field.defaults');
         foreach ($this->fields as $field) {
             rng_add_event_field_storage($field, $this->entity_type);
             rng_add_event_field_config($field, $this->getEventEntityTypeId(), $this->getEventBundle());
         }
     }
     $display = entity_get_form_display($this->entity_type, $this->bundle, 'rng_event');
     if ($display->isNew()) {
         // EntityDisplayBase::init() adds default fields. Remove them.
         foreach (array_keys($display->getComponents()) as $name) {
             if (!in_array($name, $this->fields)) {
                 $display->removeComponent($name);
             }
         }
         // Weight is the key.
         $field_weights = [EventManagerInterface::FIELD_STATUS, EventManagerInterface::FIELD_ALLOW_DUPLICATE_REGISTRANTS, EventManagerInterface::FIELD_CAPACITY, EventManagerInterface::FIELD_EMAIL_REPLY_TO, EventManagerInterface::FIELD_REGISTRATION_TYPE, EventManagerInterface::FIELD_REGISTRATION_GROUPS];
         module_load_include('inc', 'rng', 'rng.field.defaults');
         foreach ($this->fields as $name) {
             rng_add_event_form_display_defaults($display, $name);
             if (in_array($name, $field_weights)) {
                 $component = $display->getComponent($name);
                 $component['weight'] = array_search($name, $field_weights);
                 $display->setComponent($name, $component);
             }
         }
         $display->save();
     }
     // Rebuild routes and local tasks.
     \Drupal::service('router.builder')->setRebuildNeeded();
     // Rebuild local actions https://github.com/dpi/rng/issues/18
     \Drupal::service('plugin.manager.menu.local_action')->clearCachedDefinitions();
 }