From 1d29f1e5f10065b3962142638f7c80c7c4ab1c44 Mon Sep 17 00:00:00 2001 From: bach Date: Thu, 24 Jun 2021 12:12:18 +0200 Subject: [PATCH 1/3] added ids to block on pages manager layout --- .vscode/launch.json | 26 ++++++++++++ web/sites/development.services.yml | 41 +++++++++++++++++++ web/themes/custom/popsu/popsu.theme | 20 +++++++-- .../popsu/templates/layout/block.html.twig | 39 ++++++++++++++++++ .../templates/layout/layout--onecol.html.twig | 25 +++++++++++ 5 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 web/themes/custom/popsu/templates/layout/block.html.twig create mode 100644 web/themes/custom/popsu/templates/layout/layout--onecol.html.twig diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..d8aff3cd --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Listen for Xdebug", + "type": "php", + "request": "launch", + "serverSourceRoot":"192.168.0.21" + "port": 9001, + "pathMappings": { + "/var/www/d9": "${workspaceFolder}" + }, + }, + { + "name": "Launch currently open script", + "type": "php", + "request": "launch", + "program": "${file}", + "cwd": "${fileDirname}", + "port": 9001 + } + ] +} \ No newline at end of file diff --git a/web/sites/development.services.yml b/web/sites/development.services.yml index d2857c66..3788bed9 100644 --- a/web/sites/development.services.yml +++ b/web/sites/development.services.yml @@ -4,6 +4,47 @@ # 'example.settings.local.php' file, which sits next to this file. parameters: http.response.debug_cacheability_headers: true + twig.config: + # Twig debugging: + # + # When debugging is enabled: + # - The markup of each Twig template is surrounded by HTML comments that + # contain theming information, such as template file name suggestions. + # - Note that this debugging markup will cause automated tests that directly + # check rendered HTML to fail. When running automated tests, 'debug' + # should be set to FALSE. + # - The dump() function can be used in Twig templates to output information + # about template variables. + # - Twig templates are automatically recompiled whenever the source code + # changes (see auto_reload below). + # + # For more information about debugging Twig templates, see + # https://www.drupal.org/node/1906392. + # + # Not recommended in production environments + # @default false + debug: true + # Twig auto-reload: + # + # Automatically recompile Twig templates whenever the source code changes. + # If you don't provide a value for auto_reload, it will be determined + # based on the value of debug. + # + # Not recommended in production environments + # @default null + auto_reload: true + # Twig cache: + # + # By default, Twig templates will be compiled and stored in the filesystem + # to increase performance. Disabling the Twig cache will recompile the + # templates from source each time they are used. In most cases the + # auto_reload setting above should be enabled rather than disabling the + # Twig cache. + # + # Not recommended in production environments + # @default true + cache: false + services: cache.backend.null: class: Drupal\Core\Cache\NullBackendFactory diff --git a/web/themes/custom/popsu/popsu.theme b/web/themes/custom/popsu/popsu.theme index 46b85668..d3b2c5d8 100644 --- a/web/themes/custom/popsu/popsu.theme +++ b/web/themes/custom/popsu/popsu.theme @@ -35,11 +35,14 @@ function popsu_preprocess_views_view_unformatted(&$variables) { } - /*$rows = $variables['rows']; + /* + $rows = $variables['rows']; $style = $view->style_plugin; $options = $style->options; - $variables['default_row_class'] = !empty($options['default_row_class']);*/ -/* foreach ($rows as $id => $row) { + $variables['default_row_class'] = !empty($options['default_row_class']); + */ + /* + foreach ($rows as $id => $row) { $variables['rows'][$id] = array(); $variables['rows'][$id]['content'] = $row; $variables['rows'][$id]['attributes'] = new Attribute(); @@ -48,5 +51,14 @@ function popsu_preprocess_views_view_unformatted(&$variables) { $variables['rows'][$id]['attributes'] ->addClass($row_class); } - }*/ + } + */ }; + + +/** + * Implements hook_preprocess_block(). + */ +// function popsu_preprocess_block(&$variables) { +// $t="t"; +// } \ No newline at end of file diff --git a/web/themes/custom/popsu/templates/layout/block.html.twig b/web/themes/custom/popsu/templates/layout/block.html.twig new file mode 100644 index 00000000..58171e18 --- /dev/null +++ b/web/themes/custom/popsu/templates/layout/block.html.twig @@ -0,0 +1,39 @@ +{# +/** + * @file + * Default theme implementation to display a block. + * + * Available variables: + * - plugin_id: The ID of the block implementation. + * - label: The configured label of the block if visible. + * - configuration: A list of the block's configuration values. + * - label: The configured label for the block. + * - label_display: The display settings for the label. + * - provider: The module or other provider that provided this block plugin. + * - Block plugin specific settings will also be stored here. + * - content: The content of this block. + * - attributes: array of HTML attributes populated by modules, intended to + * be added to the main container tag of this template. + * - id: A valid HTML ID and guaranteed unique. + * - title_attributes: Same as attributes, except applied to the main title + * tag that appears in the template. + * - title_prefix: Additional output populated by modules, intended to be + * displayed in front of the main title tag that appears in the template. + * - title_suffix: Additional output populated by modules, intended to be + * displayed after the main title tag that appears in the template. + * + * @see template_preprocess_block() + * + * @ingroup themeable + */ +#} +
+ {{ title_prefix }} + {% if label %} + {{ label }} + {% endif %} + {{ title_suffix }} + {% block content %} + {{ content }} + {% endblock %} +
diff --git a/web/themes/custom/popsu/templates/layout/layout--onecol.html.twig b/web/themes/custom/popsu/templates/layout/layout--onecol.html.twig new file mode 100644 index 00000000..3a7f9934 --- /dev/null +++ b/web/themes/custom/popsu/templates/layout/layout--onecol.html.twig @@ -0,0 +1,25 @@ +{# +/** + * @file + * Default theme implementation to display a one-column layout. + * + * Available variables: + * - content: The content for this layout. + * - attributes: HTML attributes for the layout
. + * + * @ingroup themeable + */ +#} +{% + set classes = [ + 'layout', + 'layout--onecol', + ] +%} +{% if content %} + +
+ {{ content.content }} +
+
+{% endif %} From 28f21f179742097fba1e002b8bdb2dde4adec8c0 Mon Sep 17 00:00:00 2001 From: bach Date: Thu, 24 Jun 2021 13:42:51 +0200 Subject: [PATCH 2/3] added classes to links generated by views --- web/themes/custom/popsu/popsu.theme | 45 ++++++++++++++++++- .../views/views-view-field.html.twig | 23 ++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 web/themes/custom/popsu/templates/views/views-view-field.html.twig diff --git a/web/themes/custom/popsu/popsu.theme b/web/themes/custom/popsu/popsu.theme index d3b2c5d8..063e20c1 100644 --- a/web/themes/custom/popsu/popsu.theme +++ b/web/themes/custom/popsu/popsu.theme @@ -61,4 +61,47 @@ function popsu_preprocess_views_view_unformatted(&$variables) { */ // function popsu_preprocess_block(&$variables) { // $t="t"; -// } \ No newline at end of file +// } + +function popsu_preprocess_views_view_field(&$variables){ + // check if link to entoty option is true + $settings = $variables['field']->options['settings']; + if ($settings['link_to_entity']) { + // get the entity and build the classes + $entity = $variables['row']->_entity; + // build new classes + $new_classes = array( + $entity->getEntityTypeId(), + $entity->getEntityTypeId().'-'.$entity->bundle(), + $entity->getEntityTypeId().'-'.$entity->bundle().'-'.$entity->id() + ); + + // get the entity link and url + $link = $entity->toLink(); + $url = $entity->toLink()->getUrl(); + + // set the active_class option to the url + $url->setOption('set_active_class', true); + + // add new classes to the url (without overwriting existing once) + $options = $url->getOptions(); + if($attributes = $options['attributes']){ + if($classes = $attributes['class']){ + $attributes['class'] += $new_classes; + }else{ + $attributes['class'] = $new_classes; + } + }else{ + $attributes = array( + "class" => $new_classes + ); + } + $url->setOption('attributes', $attributes); + + // update the url of the link + $link->setUrl($url); + + // overwrite the output + $variables['output'] = $link->toRenderable(); + } +} \ No newline at end of file diff --git a/web/themes/custom/popsu/templates/views/views-view-field.html.twig b/web/themes/custom/popsu/templates/views/views-view-field.html.twig new file mode 100644 index 00000000..04a20ac5 --- /dev/null +++ b/web/themes/custom/popsu/templates/views/views-view-field.html.twig @@ -0,0 +1,23 @@ +{# +/** + * @file + * Default theme implementation for a single field in a view. + * + * Available variables: + * - view: The view that the field belongs to. + * - field: The field handler that can process the input. + * - row: The raw result of the database query that generated this field. + * - output: The processed output that will normally be used. + * + * When fetching output from the row this construct should be used: + * data = row[field.field_alias] + * + * The above will guarantee that you'll always get the correct data, regardless + * of any changes in the aliasing that might happen if the view is modified. + * + * @see template_preprocess_views_view_field() + * + * @ingroup themeable + */ +#} +{{ output -}} From f5a36bcee139f4b38f0b8b4b86845b8e4dbee64f Mon Sep 17 00:00:00 2001 From: bach Date: Thu, 24 Jun 2021 13:45:19 +0200 Subject: [PATCH 3/3] php notice fixe --- web/themes/custom/popsu/popsu.theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/themes/custom/popsu/popsu.theme b/web/themes/custom/popsu/popsu.theme index 063e20c1..651be413 100644 --- a/web/themes/custom/popsu/popsu.theme +++ b/web/themes/custom/popsu/popsu.theme @@ -85,8 +85,8 @@ function popsu_preprocess_views_view_field(&$variables){ // add new classes to the url (without overwriting existing once) $options = $url->getOptions(); - if($attributes = $options['attributes']){ - if($classes = $attributes['class']){ + if(isset($options['attributes']) && $attributes = $options['attributes']){ + if(isset($attributes['class']) && $classes = $attributes['class']){ $attributes['class'] += $new_classes; }else{ $attributes['class'] = $new_classes;