diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/row/DataFieldRow.php b/core/modules/views/lib/Drupal/views/Plugin/views/row/DataFieldRow.php index 84031d2..2c96e0d 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/row/DataFieldRow.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/row/DataFieldRow.php @@ -38,6 +38,9 @@ class DataFieldRow extends RowPluginBase { */ protected $replacementAliases = array(); + /** + * Overrides \Drupal\views\Plugin\views\row\RowPluginBase::init(). + */ public function init(ViewExecutable $view, &$display, $options = NULL) { parent::init($view, $display, $options); @@ -72,13 +75,11 @@ public function buildOptionsForm(&$form, &$form_state) { ); if ($fields = $this->view->display_handler->getOption('fields')) { - $options = $this->options; - foreach ($fields as $id => $field) { $form['aliases'][$id] = array( '#type' => 'textfield', '#title' => $id, - '#default_value' => isset($options['aliases'][$id]) ? $options['aliases'][$id] : '', + '#default_value' => isset($this->options['aliases'][$id]) ? $this->options['aliases'][$id] : '', ); } } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/style/Serialize.php b/core/modules/views/lib/Drupal/views/Plugin/views/style/Serialize.php index 6f18d0f..c8ac3b8 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/style/Serialize.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/style/Serialize.php @@ -8,6 +8,7 @@ namespace Drupal\views\Plugin\views\style; use Drupal\Core\Annotation\Plugin; +use Drupal\views\ViewExecutable; use Drupal\Core\Annotation\Translation; /** @@ -35,14 +36,43 @@ class Serialize extends StylePluginBase { protected $usesGrouping = FALSE; /** - * Overrides Drupal\views\Plugin\views\style\StylePluginBase::render(). + * The serializer which serializes the views result. + * + * @var \Symfony\Component\Serializer\Serializer */ - public function render() { + protected $serializer; + + /** + * The current active request object. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; + + /** + * The current content negotiation object registered on the container. + * + * @var \Drupal\Core\ContentNegotiation + */ + protected $negotiation; + + /** + * Overrides \Drupal\views\Plugin\views\style\StylePluginBase::init(). + */ + public function init(ViewExecutable $view, &$display, $options = NULL) { + parent::init($view, $display, $options); + // Get services for serialization. - $serializer = drupal_container()->get('serializer'); - $request = drupal_container()->get('request'); - $negotiation = drupal_container()->get('content_negotiation'); + $container = drupal_container(); + $this->serializer = $container->get('serializer'); + $this->request = $container->get('request'); + $this->negotiation = $container->get('content_negotiation'); + } + /** + * Overrides Drupal\views\Plugin\views\style\StylePluginBase::render(). + */ + public function render() { $rows = array(); // If the Data Entity row plugin is used, this will be an array of entities // which will pass through Serializer to one of the registered Normalizers, @@ -53,10 +83,10 @@ public function render() { $rows[] = $this->row_plugin->render($row); } - $content_type = $negotiation->getContentType($request); - $this->displayHandler->setContentType($request->getMimeType($content_type)); + $content_type = $this->negotiation->getContentType($this->request); + $this->displayHandler->setContentType($this->request->getMimeType($content_type)); - return $serializer->serialize($rows, $content_type); + return $this->serializer->serialize($rows, $content_type); } }