From 5a9c4bec9cc3e039e42330f00c7af2a11474aa30 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org> Date: Wed, 6 Nov 2013 11:10:09 +0000 Subject: [PATCH] Issue #2126973 by damiankloip: FATAL error in Drupal\field\Plugin\views\field\Field::groupByForm. --- .../Drupal/field/Plugin/views/field/Field.php | 13 +++-- .../Drupal/field/Tests/Views/FieldUITest.php | 48 +++++++++++++++++-- 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 4d5e3bb3e04c..d89340f61763 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -7,9 +7,11 @@ namespace Drupal\field\Plugin\views\field; +use Drupal\Component\Utility\MapArray; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityStorageControllerInterface; +use Drupal\field\Field as FieldHelper; use Drupal\Core\Entity\FieldableDatabaseStorageController; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FormatterPluginManager; @@ -137,12 +139,12 @@ public static function create(ContainerInterface $container, array $configuratio public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { parent::init($view, $display, $options); - $this->field_info = $field = field_info_field($this->definition['entity_type'], $this->definition['field_name']); + $this->field_info = FieldHelper::fieldInfo()->getField($this->definition['entity_type'], $this->definition['field_name']); $this->multiple = FALSE; $this->limit_values = FALSE; - $cardinality = $field->getFieldCardinality(); - if ($field->isFieldMultiple()) { + $cardinality = $this->field_info->getFieldCardinality(); + if ($this->field_info->isFieldMultiple()) { $this->multiple = TRUE; // If "Display all values in the same row" is FALSE, then we always limit @@ -606,9 +608,10 @@ public function buildGroupByForm(&$form, &$form_state) { parent::buildGroupByForm($form, $form_state); // With "field API" fields, the column target of the grouping function // and any additional grouping columns must be specified. + $group_columns = array( 'entity_id' => t('Entity ID'), - ) + drupal_map_assoc(array_keys($this->field_info['columns']), 'ucfirst'); + ) + MapArray::copyValuesToKeys(array_keys($this->field_info->getColumns()), 'ucfirst'); $form['group_column'] = array( '#type' => 'select', @@ -618,7 +621,7 @@ public function buildGroupByForm(&$form, &$form_state) { '#options' => $group_columns, ); - $options = drupal_map_assoc(array('bundle', 'language', 'entity_type'), 'ucfirst'); + $options = MapArray::copyValuesToKeys(array('bundle', 'language', 'entity_type'), 'ucfirst'); // Add on defined fields, noting that they're prefixed with the field name. $form['group_columns'] = array( diff --git a/core/modules/field/lib/Drupal/field/Tests/Views/FieldUITest.php b/core/modules/field/lib/Drupal/field/Tests/Views/FieldUITest.php index f2b577aa7ed4..57482276ec99 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/FieldUITest.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/FieldUITest.php @@ -28,6 +28,16 @@ class FieldUITest extends FieldTestBase { */ public static $modules = array('views_ui'); + /** + * A user with the 'administer views' permission. + * + * @var \Drupal\user\UserInterface + */ + protected $account; + + /** + * {@inheritdoc} + */ public static function getInfo() { return array( 'name' => 'Field: Field handler UI', @@ -37,15 +47,22 @@ public static function getInfo() { } /** - * Tests basic field handler settings in the UI. + * {@inheritdoc} */ - public function testHandlerUI() { - $account = $this->drupalCreateUser(array('administer views')); - $this->drupalLogin($account); + public function setUp() { + parent::setUp(); + + $this->account = $this->drupalCreateUser(array('administer views')); + $this->drupalLogin($this->account); $this->setUpFields(); $this->setUpInstances(); + } + /** + * Tests basic field handler settings in the UI. + */ + public function testHandlerUI() { $url = "admin/structure/views/nojs/config-item/test_view_fieldapi/default/field/field_name_0"; $this->drupalGet($url); @@ -76,4 +93,27 @@ public function testHandlerUI() { $this->assertEqual($view->field['field_name_0']->options['settings']['trim_length'], $random_number); } + /** + * Tests the basic field handler form when aggregation is enabled. + */ + public function testHandlerUIAggregation() { + // Enable aggregation. + $edit = array('group_by' => '1'); + $this->drupalPostForm('admin/structure/views/nojs/display/test_view_fieldapi/default/group_by', $edit, t('Apply')); + + $url = "admin/structure/views/nojs/config-item/test_view_fieldapi/default/field/field_name_0"; + $this->drupalGet($url); + $this->assertResponse(200); + + // Test the click sort column options. + // Tests the available formatter options. + $result = $this->xpath('//select[@id=:id]/option', array(':id' => 'edit-options-click-sort-column')); + $options = array_map(function($item) { + return (string) $item->attributes()->value[0]; + }, $result); + sort($options, SORT_STRING); + + $this->assertEqual($options, array('format', 'value'), 'The expected sort field options were found.'); + } + } -- GitLab