Ejemplo n.º 1
0
 /**
  * Asserts various aspects of a view mode entity.
  *
  * @param string $id
  *   The entity ID.
  * @param string $label
  *   The expected label of the view mode.
  * @param string $entity_type
  *   The expected entity type ID which owns the view mode.
  * @param bool $status
  *   The expected status of the view mode.
  */
 protected function assertEntity($id, $label, $entity_type)
 {
     /** @var \Drupal\Core\Entity\EntityViewModeInterface $view_mode */
     $view_mode = EntityViewMode::load($id);
     $this->assertTrue($view_mode instanceof EntityViewModeInterface);
     $this->assertIdentical($label, $view_mode->label());
     $this->assertIdentical($entity_type, $view_mode->getTargetType());
 }
 /**
  * Tests Drupal 6 view modes to Drupal 8 migration.
  */
 public function testViewModes()
 {
     // Test a new view mode.
     $view_mode = EntityViewMode::load('node.preview');
     $this->assertIdentical(FALSE, is_null($view_mode), 'Preview view mode loaded.');
     $this->assertIdentical('Preview', $view_mode->label(), 'View mode has correct label.');
     // Test the Id Map.
     $this->assertIdentical(array('node', 'preview'), entity_load('migration', 'd6_view_modes')->getIdMap()->lookupDestinationID(array(1)));
 }
Ejemplo n.º 3
0
 /**
  * Tests migrating D7 view modes, then rolling back.
  */
 public function testMigration()
 {
     // Test that the view modes have migrated (prior to rollback).
     parent::testMigration();
     $this->executeRollback('d7_view_modes');
     // Check that view modes have been rolled back.
     $view_mode_ids = ['comment.full', 'node.teaser', 'node.full', 'user.full'];
     foreach ($view_mode_ids as $view_mode_id) {
         $this->assertNull(EntityViewMode::load($view_mode_id));
     }
 }
Ejemplo n.º 4
0
 /**
  * Tests changing the row plugin and changing some options of a row.
  */
 public function testRowUI()
 {
     $view_name = 'test_view';
     $view_edit_url = "admin/structure/views/view/{$view_name}/edit";
     $row_plugin_url = "admin/structure/views/nojs/display/{$view_name}/default/row";
     $row_options_url = "admin/structure/views/nojs/display/{$view_name}/default/row_options";
     $this->drupalGet($row_plugin_url);
     $this->assertFieldByName('row[type]', 'fields', 'The default row plugin selected in the UI should be fields.');
     $edit = array('row[type]' => 'test_row');
     $this->drupalPostForm(NULL, $edit, t('Apply'));
     $this->assertFieldByName('row_options[test_option]', NULL, 'Make sure the custom settings form from the test plugin appears.');
     $random_name = $this->randomMachineName();
     $edit = array('row_options[test_option]' => $random_name);
     $this->drupalPostForm(NULL, $edit, t('Apply'));
     $this->drupalGet($row_options_url);
     $this->assertFieldByName('row_options[test_option]', $random_name, 'Make sure the custom settings form field has the expected value stored.');
     $this->drupalPostForm($view_edit_url, array(), t('Save'));
     $this->assertLink(t('Test row plugin'), 0, 'Make sure the test row plugin is shown in the UI');
     $view = Views::getView($view_name);
     $view->initDisplay();
     $row = $view->display_handler->getOption('row');
     $this->assertEqual($row['type'], 'test_row', 'Make sure that the test_row got saved as used row plugin.');
     $this->assertEqual($row['options']['test_option'], $random_name, 'Make sure that the custom settings field got saved as expected.');
     // Change the row plugin to fields using ajax.
     // Note: this is the best approximation we can achieve, because we cannot
     // simulate the 'openDialog' command in
     // WebTestBase::drupalProcessAjaxResponse(), hence we have to make do.
     $row_plugin_url_ajax = str_replace('/nojs/', '/ajax/', $row_plugin_url);
     $ajax_settings = ['accepts' => 'application/vnd.drupal-ajax', 'submit' => ['_triggering_element_name' => 'op', '_triggering_element_value' => 'Apply'], 'url' => $row_plugin_url_ajax];
     $this->drupalPostAjaxForm($row_plugin_url, ['row[type]' => 'fields'], NULL, $row_plugin_url_ajax, [], [], NULL, $ajax_settings);
     $this->drupalGet($row_plugin_url);
     $this->assertResponse(200);
     $this->assertFieldByName('row[type]', 'fields', 'Make sure that the fields got saved as used row plugin.');
     // Ensure that entity row plugins appear.
     $view_name = 'content';
     $row_plugin_url = "admin/structure/views/nojs/display/{$view_name}/default/row";
     $row_options_url = "admin/structure/views/nojs/display/{$view_name}/default/row_options";
     $this->drupalGet($row_plugin_url);
     $this->assertFieldByName('row[type]', 'entity:node');
     $this->drupalPostForm(NULL, ['row[type]' => 'entity:node'], t('Apply'));
     $this->assertUrl($row_options_url);
     $this->assertFieldByName('row_options[view_mode]', 'teaser');
     // Change the teaser label to have markup so we can test escaping.
     $teaser = EntityViewMode::load('node.teaser');
     $teaser->set('label', 'Teaser <em>markup</em>');
     $teaser->save();
     $this->drupalGet('admin/structure/views/view/frontpage/edit/default');
     $this->assertEscaped('Teaser <em>markup</em>');
 }
Ejemplo n.º 5
0
 /**
  * Tests view mode setting integration.
  *
  * @see comment_entity_view_display_presave()
  * @see CommentDefaultFormatter::calculateDependencies()
  */
 public function testViewMode()
 {
     $mode = Unicode::strtolower($this->randomMachineName());
     // Create a new comment view mode and a view display entity.
     EntityViewMode::create(['id' => "comment.{$mode}", 'targetEntityType' => 'comment', 'settings' => ['comment_type' => 'comment']])->save();
     EntityViewDisplay::create(['targetEntityType' => 'comment', 'bundle' => 'comment', 'mode' => $mode])->setStatus(TRUE)->save();
     // Create a comment field attached to a host 'entity_test' entity.
     FieldStorageConfig::create(['entity_type' => 'entity_test', 'type' => 'comment', 'field_name' => $field_name = Unicode::strtolower($this->randomMachineName()), 'settings' => ['comment_type' => 'comment']])->save();
     FieldConfig::create(['entity_type' => 'entity_test', 'bundle' => 'entity_test', 'field_name' => $field_name])->save();
     $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.
     $this->assertNull($host_display->getComponent($field_name));
     $this->assertTrue($host_display->get('hidden')[$field_name]);
     // Check that the proper warning has been logged.
     $arguments = ['@id' => $host_display_id, '@name' => $field_name, '@display' => EntityViewMode::load("comment.{$mode}")->label(), '@mode' => $mode];
     $logged = (bool) Database::getConnection()->select('watchdog')->fields('watchdog', ['wid'])->condition('type', 'system')->condition('message', "View display '@id': Comment field formatter '@name' was disabled because it is using the comment view display '@display' (@mode) that was just disabled.")->condition('variables', serialize($arguments))->execute()->fetchField();
     $this->assertTrue($logged);
     // Re-enable the comment view display.
     EntityViewDisplay::load($comment_display_id)->setStatus(TRUE)->save();
     // Re-enable the comment field formatter on host entity view display.
     EntityViewDisplay::load($host_display_id)->setComponent($field_name, $component)->save();
     // Delete the "comment.$mode" view mode.
     EntityViewMode::load("comment.{$mode}")->delete();
     // Check that the comment view display entity has been deleted too.
     $this->assertNull(EntityViewDisplay::load($comment_display_id));
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
     $host_display = EntityViewDisplay::load($host_display_id);
     // Check that the field formatter has been disabled on host view display.
     $this->assertNull($host_display->getComponent($field_name));
     $this->assertTrue($host_display->get('hidden')[$field_name]);
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function onDependencyRemoval(array $dependencies)
 {
     // All dependencies of this processor are entity view modes, so we go
     // through our configuration and remove the settings for all datasources or
     // bundles which were set to one of the removed view modes. This will always
     // result in the removal of all those dependencies.
     // The code is highly similar to calculateDependencies(), only that we
     // remove the setting (if necessary) instead of adding a dependency.
     $view_modes = $this->configuration['view_mode'];
     foreach ($this->index->getDatasources() as $datasource_id => $datasource) {
         if ($entity_type_id = $datasource->getEntityTypeId() && !empty($view_modes[$datasource_id])) {
             foreach ($view_modes[$datasource_id] as $bundle => $view_mode_id) {
                 if ($view_mode_id) {
                     /** @var \Drupal\Core\Entity\EntityViewModeInterface $view_mode */
                     $view_mode = EntityViewMode::load($entity_type_id . '.' . $view_mode_id);
                     if ($view_mode) {
                         $dependency_key = $view_mode->getConfigDependencyKey();
                         $dependency_name = $view_mode->getConfigDependencyName();
                         if (!empty($dependencies[$dependency_key][$dependency_name])) {
                             unset($this->configuration['view_mode'][$datasource_id][$bundle]);
                         }
                     }
                 }
             }
         }
     }
     return TRUE;
 }