Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
prototype
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
prototype
Commits
257f8737
Commit
257f8737
authored
6 months ago
by
Jennifer Dust
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3483019
by jldust, droath: Add views theme suggestions
parent
d6013e0b
No related branches found
No related tags found
1 merge request
!151
Adding view suggestion and reordered theme file
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
prototype.theme
+134
-118
134 additions, 118 deletions
prototype.theme
with
134 additions
and
118 deletions
prototype.theme
+
134
−
118
View file @
257f8737
...
...
@@ -7,53 +7,53 @@
use
Drupal\block_content
\BlockContentInterface
;
use
Drupal\Component\Utility\Html
;
use
Drupal\views\ViewExecutable
;
/**
* Implements hook_preprocess_page() for prototype theme.
*
* @param array &$variables
* An associative array containing the variables for the page template.
*
* NOTE: If you want to use this outside the footer, you need to
* rename this function to prototype_preprocess_page and adjust the
* region--footer.html.twig file and add the backToTop variable to the
* page.html.twig file.
* This preprocess adds the current page title to the end of a breadcrumb list.
*/
function
prototype_preprocess_region__footer
(
array
&
$variables
)
{
function
prototype_preprocess_breadcrumb
(
&
$variables
)
{
if
(
$variables
[
'breadcrumb'
])
{
$request
=
\Drupal
::
request
();
$route_match
=
\Drupal
::
routeMatch
();
$page_title
=
\Drupal
::
service
(
'title_resolver'
)
->
getTitle
(
$request
,
$route_match
->
getRouteObject
());
if
(
theme_get_setting
(
'display_back_to_top'
))
{
$variables
[
'backToTop'
]
=
[
'#type'
=>
'component'
,
'#component'
=>
'prototype:back-to-top'
,
'#props'
=>
[
'text'
=>
t
(
'Back to Top'
),
],
];
if
(
!
empty
(
$page_title
))
{
$breadcrumb_link
=
[
'text'
=>
$page_title
,
'url'
=>
''
,
'attributes'
=>
[
'class'
=>
'active'
],
'is_current'
=>
TRUE
,
];
// Add cache metadata.
$breadcrumb_link
[
'#cache'
]
=
[
'contexts'
=>
[
'url.path'
],
'tags'
=>
[
'config:system.site'
],
];
$variables
[
'breadcrumb'
][]
=
$breadcrumb_link
;
}
}
}
/**
* Implements hook_
theme_suggestions_HOOK_alter
().
* Implements hook_
preprocess_HOOK
().
*/
function
prototype_theme_suggestions_block_alter
(
array
&
$suggestions
,
array
$variables
)
{
$content
=
$variables
[
'elements'
][
'content'
];
if
(
isset
(
$content
[
'#block_content'
])
&&
$content
[
'#block_content'
]
instanceof
BlockContentInterface
)
{
$suggestions
[]
=
'block__block_content__'
.
$content
[
'#block_content'
]
->
bundle
();
}
function
prototype_preprocess_checkboxes
(
&
$variables
)
{
$variables
[
'attributes'
][
'class'
][]
=
'form-boolean-group'
;
}
/**
* Implements
theme_theme_suggestions_input_alter
().
* Implements
hook_preprocess_HOOK
().
*/
function
prototype_
theme_suggestions_input_alter
(
&
$suggestions
,
array
$variables
)
{
$
element
=
$variables
[
'element
'
];
function
prototype_
preprocess_field
(
&
$variables
)
{
$
rich_field_types
=
[
'text_with_summary'
,
'text'
,
'text_long
'
];
// Add Twig template suggestion based on data attributes. To use this, in a
// `hook_form_alter()` add an element to the `#attributes` array for
// `data-twig-suggestion`. `button` elements have a template already made.
if
(
isset
(
$element
[
'#attributes'
][
'data-twig-suggestion'
]))
{
$suggestions
[]
=
"input__
{
$element
[
'#type'
]
}
__
{
$element
[
'#attributes'
][
'data-twig-suggestion'
]
}
"
;
if
(
in_array
(
$variables
[
'field_type'
],
$rich_field_types
,
TRUE
))
{
$variables
[
'attributes'
][
'class'
][]
=
'text-content'
;
}
}
...
...
@@ -128,50 +128,6 @@ function prototype_preprocess_input(&$variables) {
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function
prototype_preprocess_textarea
(
&
$variables
)
{
$variables
[
'attributes'
][
'class'
][]
=
'form-element'
;
$variables
[
'attributes'
][
'class'
][]
=
'form-element--type-textarea'
;
$variables
[
'attributes'
][
'class'
][]
=
'form-element--api-textarea'
;
}
/**
* Implements hook_preprocess_HOOK().
*/
function
prototype_preprocess_select
(
&
$variables
)
{
$variables
[
'attributes'
][
'class'
][]
=
'form-element'
;
$variables
[
'attributes'
][
'class'
][]
=
$variables
[
'element'
][
'#multiple'
]
?
'form-element--type-select-multiple'
:
'form-element--type-select'
;
}
/**
* Implements hook_preprocess_HOOK().
*/
function
prototype_preprocess_checkboxes
(
&
$variables
)
{
$variables
[
'attributes'
][
'class'
][]
=
'form-boolean-group'
;
}
/**
* Implements hook_preprocess_HOOK().
*/
function
prototype_preprocess_radios
(
&
$variables
)
{
$variables
[
'attributes'
][
'class'
][]
=
'form-boolean-group'
;
}
/**
* Implements hook_preprocess_HOOK().
*/
function
prototype_preprocess_field
(
&
$variables
)
{
$rich_field_types
=
[
'text_with_summary'
,
'text'
,
'text_long'
];
if
(
in_array
(
$variables
[
'field_type'
],
$rich_field_types
,
TRUE
))
{
$variables
[
'attributes'
][
'class'
][]
=
'text-content'
;
}
}
/**
* Implements hook_preprocess_menu().
*/
...
...
@@ -186,28 +142,6 @@ function prototype_preprocess_menu(&$variables) {
prototype_prepare_menu_items
(
$variables
[
'items'
]);
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function
prototype_theme_suggestions_taxonomy_term_alter
(
array
&
$suggestions
,
array
$variables
)
{
$view_mode
=
$variables
[
'elements'
][
'#view_mode'
];
$suggestions
[]
=
'taxonomy_term__'
.
$view_mode
;
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*
* @todo remove after these are resolved:
* https://www.drupal.org/project/drupal/issues/2270883
* https://www.drupal.org/project/drupal/issues/2766379
*/
function
prototype_theme_suggestions_user_alter
(
array
&
$suggestions
,
array
$variables
)
{
$view_mode
=
$variables
[
'elements'
][
'#view_mode'
]
??
''
;
if
(
$view_mode
)
{
$suggestions
[]
=
'user__'
.
$view_mode
;
}
}
/**
* Helper function to standarize gaps in the menu markup.
*
...
...
@@ -254,35 +188,117 @@ function prototype_prepare_menu_items(&$items) {
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function
prototype_preprocess_radios
(
&
$variables
)
{
$variables
[
'attributes'
][
'class'
][]
=
'form-boolean-group'
;
}
/**
* Implements hook_preprocess_page() for prototype theme.
*
* This preprocess adds the current page title to the end of a breadcrumb list.
*
* @param array &$variables
* An associative array containing the variables for the page template.
*
* NOTE: If you want to use this outside the footer, you need to
* rename this function to prototype_preprocess_page and adjust the
* region--footer.html.twig file and add the backToTop variable to the
* page.html.twig file.
*/
function
prototype_preprocess_breadcrumb
(
&
$variables
)
{
if
(
$variables
[
'breadcrumb'
])
{
$request
=
\Drupal
::
request
();
$route_match
=
\Drupal
::
routeMatch
();
$page_title
=
\Drupal
::
service
(
'title_resolver'
)
->
getTitle
(
$request
,
$route_match
->
getRouteObject
());
function
prototype_preprocess_region__footer
(
array
&
$variables
)
{
if
(
!
empty
(
$page_title
))
{
$breadcrumb_link
=
[
'text'
=>
$page_title
,
'url'
=>
''
,
'attributes'
=>
[
'class'
=>
'active'
],
'is_current'
=>
TRUE
,
];
if
(
theme_get_setting
(
'display_back_to_top'
))
{
$variables
[
'backToTop'
]
=
[
'#type'
=>
'component'
,
'#component'
=>
'prototype:back-to-top'
,
'#props'
=>
[
'text'
=>
t
(
'Back to Top'
),
],
];
}
}
// Add cache metadata.
$breadcrumb_link
[
'#cache'
]
=
[
'contexts'
=>
[
'url.path'
],
'tags'
=>
[
'config:system.site'
],
];
/**
* Implements hook_preprocess_HOOK().
*/
function
prototype_preprocess_select
(
&
$variables
)
{
$variables
[
'attributes'
][
'class'
][]
=
'form-element'
;
$variables
[
'attributes'
][
'class'
][]
=
$variables
[
'element'
][
'#multiple'
]
?
'form-element--type-select-multiple'
:
'form-element--type-select'
;
}
$variables
[
'breadcrumb'
][]
=
$breadcrumb_link
;
}
/**
* Implements hook_preprocess_HOOK().
*/
function
prototype_preprocess_textarea
(
&
$variables
)
{
$variables
[
'attributes'
][
'class'
][]
=
'form-element'
;
$variables
[
'attributes'
][
'class'
][]
=
'form-element--type-textarea'
;
$variables
[
'attributes'
][
'class'
][]
=
'form-element--api-textarea'
;
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function
prototype_theme_suggestions_block_alter
(
array
&
$suggestions
,
array
$variables
)
{
$content
=
$variables
[
'elements'
][
'content'
];
if
(
isset
(
$content
[
'#block_content'
])
&&
$content
[
'#block_content'
]
instanceof
BlockContentInterface
)
{
$suggestions
[]
=
'block__block_content__'
.
$content
[
'#block_content'
]
->
bundle
();
}
}
/**
* Implements theme_theme_suggestions_input_alter().
*/
function
prototype_theme_suggestions_input_alter
(
&
$suggestions
,
array
$variables
)
{
$element
=
$variables
[
'element'
];
// Add Twig template suggestion based on data attributes. To use this, in a
// `hook_form_alter()` add an element to the `#attributes` array for
// `data-twig-suggestion`. `button` elements have a template already made.
if
(
isset
(
$element
[
'#attributes'
][
'data-twig-suggestion'
]))
{
$suggestions
[]
=
"input__
{
$element
[
'#type'
]
}
__
{
$element
[
'#attributes'
][
'data-twig-suggestion'
]
}
"
;
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function
prototype_theme_suggestions_taxonomy_term_alter
(
array
&
$suggestions
,
array
$variables
)
{
$view_mode
=
$variables
[
'elements'
][
'#view_mode'
];
$suggestions
[]
=
'taxonomy_term__'
.
$view_mode
;
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*
* @todo remove after these are resolved:
* https://www.drupal.org/project/drupal/issues/2270883
* https://www.drupal.org/project/drupal/issues/2766379
*/
function
prototype_theme_suggestions_user_alter
(
array
&
$suggestions
,
array
$variables
)
{
$view_mode
=
$variables
[
'elements'
][
'#view_mode'
]
??
''
;
if
(
$view_mode
)
{
$suggestions
[]
=
'user__'
.
$view_mode
;
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function
prototype_theme_suggestions_views_view_alter
(
array
&
$suggestions
,
array
$variables
)
{
$view
=
$variables
[
'view'
];
if
(
$view
instanceof
ViewExecutable
&&
$display
=
$view
->
current_display
)
{
$view_id
=
$view
->
id
();
$original
=
$variables
[
'theme_hook_original'
];
$suggestions
[]
=
"
{
$original
}
__
$view_id
"
;
$suggestions
[]
=
"
{
$original
}
__
{
$view_id
}
__
$display
"
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment