Skip to content
Snippets Groups Projects
Commit 7d7401a8 authored by codebymikey's avatar codebymikey Committed by Stephen Mustgrave
Browse files

Issue #3299447: Automated Drupal 10 compatibility fixes

parent 27bb5bcb
No related branches found
No related tags found
1 merge request!2Issue #3299447: Automated Drupal 10 compatibility fixes
CONTENTS OF THIS FILE
---------------------
* Introduction
* Requirements
* Installation
* Configuration
* Maintainers
INTRODUCTION
------------
Creates fieldset (and details and div) in Views fields output, to group fields,
by adding a new field: "Global: Fieldset" and a few preprocessors. Also
introduces a new template: views-fieldsets-fieldset.tpl.php where you can
customize your fieldset output.
* For a full description of the module, visit the project page:
https://www.drupal.org/project/views_fieldsets
* To submit bug reports and feature suggestions, or to track changes:
https://www.drupal.org/project/issues/views_fieldsets
REQUIREMENTS
------------
This module requires no modules outside of Drupal core.
INSTALLATION
------------
* Install the Views fieldsets module as you would normally install a
contributed Drupal module. Visit
https://www.drupal.org/node/1897420 for further information.
CONFIGURATION
-------------
1. Navigate to Administration > Extend and enable the module.
2. Navigate to Administration > Structure > views and open existing view or
a create a new view.
3. Add some fields.
4. Add field "Global: Fieldset" and customize settings (html tag,
collapsible, tokens etc)
5. Rearrange fields to drag normal fields under Fieldset fields. You can
nest fieldsets. The result will be visible in Preview.
Theming:
There are several new templates. You can specify the filename the Views way. See
Theme: Information for theme hook suggestion specifics. Available:
* views-fieldsets-fieldset.tpl.php
* views-fieldsets-fieldset--events.tpl.php
* views-fieldsets-fieldset--default.tpl.php (all tags)
* views-fieldsets-fieldset--default.tpl.php (per tag)
* views-fieldsets-fieldset--page.tpl.php
* views-fieldsets-fieldset--events--page.tpl.php
And of course the related preprocessors:
```
template_preprocess_views_fieldsets_fieldset(),
template_preprocess_views_fieldsets_fieldset__events() etc.
```
MAINTAINERS
-----------
* rudiedirkx - https://www.drupal.org/u/rudiedirkx
Supporting organizations:
* GOLEMS GABB - https://www.drupal.org/golems-gabb
{
"name": "drupal/views_fieldsets",
"description": "Adds fieldsets to Views.",
"type": "drupal-module",
"license": "GPL-2.0-or-later",
"minimum-stability": "dev",
"homepage": "https://drupal.org/project/views_fieldsets",
"support": {
"issues": "https://www.drupal.org/project/issues/views_fieldsets",
"source": "https://git.drupalcode.org/project/views_fieldsets"
}
}
......@@ -10,6 +10,8 @@ use Drupal\views\ViewExecutable;
use Drupal\views_fieldsets\RowFieldset;
/**
* {@inheritdoc}
*
* @ingroup views_field_handlers.
*
* @ViewsField("fieldset").
......@@ -19,7 +21,7 @@ class Fieldset extends FieldPluginBase {
/**
* {@inheritdoc}
*/
static public function getUIFieldParents(array $fields, $field_name) {
public static function getUiFieldParents(array $fields, $field_name) {
$parents = [];
$current_field = $field_name;
while ($parent = self::getUIFieldParent($fields, $current_field)) {
......@@ -32,14 +34,14 @@ class Fieldset extends FieldPluginBase {
/**
* {@inheritdoc}
*/
static public function getUIFieldParent(array $fields, $field_name) {
public static function getUiFieldParent(array $fields, $field_name) {
return $fields[$field_name];
}
/**
* {@inheritdoc}
*/
static public function getFieldParents(ViewExecutable $view, $field_name) {
public static function getFieldParents(ViewExecutable $view, $field_name) {
$parents = [];
$current_field = $field_name;
while ($parent = self::getFieldParent($view, $current_field)) {
......@@ -52,7 +54,7 @@ class Fieldset extends FieldPluginBase {
/**
* {@inheritdoc}
*/
static public function getFieldParent(ViewExecutable $view, $field_name) {
public static function getFieldParent(ViewExecutable $view, $field_name) {
$fieldsets = self::getAllFieldsets($view);
foreach ($fieldsets as $fieldset_name => $fieldset) {
if (in_array($field_name, $fieldset->getChildren())) {
......@@ -65,7 +67,7 @@ class Fieldset extends FieldPluginBase {
/**
* {@inheritdoc}
*/
static public function getWrapperTypes() {
public static function getWrapperTypes() {
$types = &drupal_static(__METHOD__);
if (!$types) {
// @todo Get from hook_theme() definitions?
......@@ -81,7 +83,7 @@ class Fieldset extends FieldPluginBase {
/**
* {@inheritdoc}
*/
static public function isFieldsetView(ViewExecutable $view) {
public static function isFieldsetView(ViewExecutable $view) {
foreach ($view->field as $field) {
if ($field instanceof self) {
return TRUE;
......@@ -93,7 +95,7 @@ class Fieldset extends FieldPluginBase {
/**
* {@inheritdoc}
*/
static public function getAllFieldsets(ViewExecutable $view) {
public static function getAllFieldsets(ViewExecutable $view) {
return array_filter($view->field, function ($field) {
return $field instanceof self;
});
......@@ -102,7 +104,7 @@ class Fieldset extends FieldPluginBase {
/**
* {@inheritdoc}
*/
static public function replaceFieldsetHandlers(ViewExecutable $view, array &$fields, ResultRow $row) {
public static function replaceFieldsetHandlers(ViewExecutable $view, array &$fields, ResultRow $row) {
$fieldsets = self::getAllFieldsets($view);
// Replace Fieldsets.
foreach ($fields as $name => $field) {
......@@ -187,7 +189,9 @@ class Fieldset extends FieldPluginBase {
'#title' => $this->t('Collapsed'),
'#default_value' => $this->options['collapsed'],
];
// Available tokens list. Not as pretty as FieldPluginBase, because it doesn't have a reusable method.
/* Available tokens list. Not as pretty as FieldPluginBase,
* because it doesn't have a reusable method.
*/
$form['tokens'] = [
'#theme' => 'item_list',
'#title' => $this->t('Replacement patterns'),
......@@ -201,7 +205,10 @@ class Fieldset extends FieldPluginBase {
* {@inheritdoc}
*/
public function render(ResultRow $values) {
// This will be overridden in RowFieldset::render(), which is called by magic through $field->content.
/*
* This will be overridden in RowFieldset::render(),
* which is called by magic through $field->content.
*/
return '[' . implode('|', $this->getChildren()) . ']';
}
......
......@@ -3,10 +3,14 @@
namespace Drupal\views_fieldsets;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Render\Markup;
use Drupal\views\ResultRow;
use Drupal\views_fieldsets\Plugin\views\field\Fieldset;
/**
* {@inheritdoc}
*/
class RowFieldset {
public $row;
......@@ -40,7 +44,8 @@ class RowFieldset {
* Method's name.
*/
public function __get($name) {
if (is_callable($method = [$this, "get_$name"])) {
$method_name = 'get' . Unicode::ucwords($name);
if (is_callable($method = [$this, $method_name])) {
return call_user_func($method);
}
if (!empty($name) && !empty($this->properties[$name])) {
......@@ -50,23 +55,23 @@ class RowFieldset {
}
/**
* Object get_content().
* Object getcontent().
*/
public function get_content() {
public function getContent() {
return $this->render();
}
/**
* Object get_wrapper_element().
* Object getwrapperelement().
*/
public function get_wrapper_element() {
public function getWrapperelement() {
return '';
}
/**
* Object get_element_type().
* Object getelementtype().
*/
public function get_element_type() {
public function getElementtype() {
return '';
}
......@@ -80,10 +85,15 @@ class RowFieldset {
'#fields' => $this->children,
'#legend' => Markup::create($this->getLegend()),
'#collapsible' => (bool) $this->handler->options['collapsible'],
'#collapsed' => (bool) $this->handler->options['collapsed'],
'#classes' => $this->getClasses(),
'#attributes' => [
'class' => $this->getClasses(),
],
];
return render($element);
if ($this->handler->options['collapsed'] && $this->getWrapperType() != 'div') {
$element['#attributes']['class'][] = 'collapsed';
}
return \Drupal::service('renderer')->render($element);
}
/**
......@@ -115,7 +125,8 @@ class RowFieldset {
$classes = array_map(function ($class) {
return Html::getClass($this->tokenize($class));
}, $classes);
return implode(' ', $classes);
return $classes;
}
/**
......@@ -133,8 +144,8 @@ class RowFieldset {
*
* @param array $fields
* Fields.
* @param array $field_name
* Fields name.
* @param string $field_name
* Field name.
*/
public function addChild(array $fields, $field_name) {
$this->children[$field_name] = $fields[$field_name];
......
<details class="{{ classes }}" {% if not collapsed %}open{% endif %}>
<details {{ attributes }}>
{% if legend %}
<summary>{{ legend }}</summary>
{% endif %}
......
<div class="{{ classes }}">
<div {{ attributes }}>
{% include 'views-view-fields.html.twig' %}
</div>
<fieldset class="{{ classes }} {% if collapsed %}collapsed{% endif %}">
<fieldset {{ attributes }}>
{% if legend %}
<legend>{{ legend }}</legend>
{% endif %}
......
name: Views fieldsets
name: Views Fieldsets
type: module
description: Adds fieldsets to Views.
package: Views
core: 8.x
core_version_requirement: '>=9'
......@@ -36,14 +36,14 @@ function views_fieldsets_help($route_name, RouteMatchInterface $route_match) {
* Implements hook_theme().
*/
function views_fieldsets_theme() {
$vars = ['fields' => [], 'classes' => ''];
$path = drupal_get_path('module', 'views_fieldsets');
$vars = ['fields' => [], 'attributes' => []];
$path = \Drupal::service('extension.list.module')->getPath('views_fieldsets');
$hooks['views_fieldsets_fieldset'] = [
'variables' => $vars + [
'legend' => '',
'collapsible' => TRUE,
'collapsed' => FALSE,
],
'legend' => '',
'collapsible' => TRUE,
'collapsed' => FALSE,
],
'template' => 'views-fieldsets-fieldset',
'path' => $path,
];
......@@ -87,6 +87,8 @@ function views_fieldsets_preprocess_views_view_fields(&$vars) {
*/
function views_fieldsets_views_ui_display_tab_alter(&$build, ViewUI $ui_view, $display_id) {
$view = $ui_view->getExecutable();
// Re-init handlers.
$view->inited = FALSE;
$view->build($display_id);
$ui_view->set('executable', $view);
if (Fieldset::isFieldsetView($view)) {
......@@ -146,15 +148,15 @@ function views_fieldsets_form_views_ui_rearrange_form_alter(&$form, &$form_state
'#attributes' => ['class' => ['field-name']],
],
'hierarchy' => $debug_tabledrag + [
'#type' => 'hidden',
'#default_value' => Fieldset::getFieldParent($view, $field_name),
'#attributes' => ['class' => ['hierarchy']],
],
'#type' => 'hidden',
'#default_value' => Fieldset::getFieldParent($view, $field_name),
'#attributes' => ['class' => ['hierarchy']],
],
'depth' => $debug_tabledrag + [
'#type' => 'hidden',
'#default_value' => $depth,
'#attributes' => ['class' => ['depth']],
],
'#type' => 'hidden',
'#default_value' => $depth,
'#attributes' => ['class' => ['depth']],
],
];
unset($row);
}
......@@ -178,6 +180,7 @@ function views_fieldsets_form_views_ui_rearrange_form_alter(&$form, &$form_state
'relationship' => 'sibling',
'group' => 'weight',
];
$form['actions']['submit']['#submit'][] = 'views_fieldsets_views_ui_rearrange_form_submit';
}
......@@ -189,6 +192,8 @@ function views_fieldsets_views_ui_rearrange_form_submit($form, $form_state) {
$display_id = $form_state->get('display_id');
$view = $ui_view->getExecutable();
$view->setDisplay($display_id);
// Re-init handlers.
$view->inited = FALSE;
$view->build($display_id);
$fieldsets = Fieldset::getAllFieldsets($view);
// Sort 1-dimensionally (wrong overall, but right per level).
......@@ -202,7 +207,7 @@ function views_fieldsets_views_ui_rearrange_form_submit($form, $form_state) {
// Sort overall: level by level, n-dimensionally following the tree down.
$input_fields_weights = [];
foreach ($input_fields as $field_name => $fieldset) {
$parents = Fieldset::getUIFieldParents($input_fields, $field_name);
$parents = Fieldset::getUiFieldParents($input_fields, $field_name);
$id = array_reverse(array_merge([$field_name], $parents));
$id = array_map(function ($field) use ($fields_order) {
return array_search($field, $fields_order);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment