123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <?php
- /**
- * @file
- * Functions to support theming in the materio theme.
- */
- use Drupal\Core\Url;
- use Drupal\Core\Link;
- use Drupal\Core\Form\FormStateInterface;
- use Drupal\Core\Template\Attribute;
- use Drupal\Component\Utility\Unicode;
- use Drupal\Core\Render\Element;
- /**
- * Implements hook_page_attachments().
- * @param array $attachments
- */
- // this does not work with themes
- // function materiotheme_page_attachments(array &$attachments) {
- // dpm('materiotheme_page_attachments', $attachments);
- // }
- /**
- * Prepares variables for HTML document templates.
- *
- * Default template: html.html.twig.
- *
- * @param array $variables
- * An associative array containing:
- * - page: A render element representing the page.
- */
- function materiotheme_preprocess_html(&$vars) {
- // $head_title = $vars['head_title'];
- // dpm($vars);
- $site_config = \Drupal::config('system.site');
- // dpm($site_config->get('slogan'));
- // array_push($head_title, [
- // 'name' => $site_config->get('name'),
- // ]);
- // $vars['head_title'] = $head_title;
- // $title = "The new title";
- // $request = \Drupal::request();
- // if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) {
- // $route->setDefault('_title', $title);
- // }
- global $base_url;
- $theme = \Drupal::theme()->getActiveTheme();
- $vars['#attached']['drupalSettings']['path']['themePath'] = $base_url .'/'. $theme->getPath();
- $description = [
- '#tag' => 'meta',
- '#attributes' => [
- 'name' => 'description',
- 'content' => $site_config->get('slogan'),
- ],
- ];
- $vars['page']['#attached']['html_head'][] = [$description, 'description'];
- // $gv = [
- // '#tag' => 'meta',
- // '#attributes' => [
- // 'name' => 'google-site-verification',
- // 'content' => "Y6PSbMfj67bXtMRAT-mFTAxrIeZPzC5jWSpH3M7yhkk",
- // ],
- // ];
- // $vars['page']['#attached']['html_head'][] = [$gv, "google-site-verification"];
- }
- function materiotheme_preprocess_page(&$vars){
- // dsm($vars, 'vars');
- }
- // function materiotheme_preprocess_node(&$vars){
- // $node = $vars['elements']['#node'];
- // $options = ['absolute' => TRUE];
- // $url = Url::fromRoute('entity.node.canonical', ['node' => $node->id()], $options);
- // $system_path = $url->getInternalPath();
- // $vars['link_attributes'] = new Attribute(array(
- // 'data-drupal-link-system-path' => $system_path=='' ? '<front>' : $system_path
- // ));
- // }
- // function materiotheme_preprocess_node_materiau_teaser(&$vars){
- // $vars['attributes']['class'] = 'card';
- // kint($vars['attributes']);
- // }
- /**
- * Implements hook_form_alter
- */
- function materiotheme_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) {
- // dpm($form_id, 'form_id');
- // dpm($form, 'form');
- $form['name']['#attributes']['placeholder'] = (string) $form['name']['#title'];
- unset($form['name']['#title']);
- $form['pass']['#attributes']['placeholder'] = (string) $form['pass']['#title'];
- unset($form['pass']['#title']);
- }
- /**
- * Implements hook_theme_suggestions_HOOK_alter().
- */
- /**
- * Prepares variables for image formatter templates.
- *
- * Default template: image-formatter.html.twig.
- *
- * @param array $variables
- * An associative array containing:
- * - item: An ImageItem object.
- * - item_attributes: An optional associative array of html attributes to be
- * placed in the img tag.
- * - image_style: An optional image style.
- * - url: An optional \Drupal\Core\Url object.
- */
- // function materiotheme_preprocess_image_formatter(&$vars){
- // if(isset($vars['url'])){
- // $system_path = $vars['url']->getInternalPath();
- // $vars['link_attributes'] = new Attribute(array(
- // 'data-drupal-link-system-path' => $system_path=='' ? '<front>' : $system_path,
- // 'class' => array('ajax-link')
- // ));
- // // dpm($vars);
- // }
- // }
- // function materiotheme_preprocess_links__language_block(&$vars){
- // // dpm($vars);
- // // foreach ($vars['links'] as $lang_code => $link) {
- // // $vars['links'][$lang_code]['text'] = $lang_code;
- // // $vars['links'][$lang_code]['link']['#title'] = $lang_code;
- // // }
- // }
- function materiotheme_theme_suggestions_taxonomy_term_alter(&$suggestions, &$vars){
- // ksm($suggestions);
- // ksm($vars);
- $original = $vars['theme_hook_original'];
- $bundle = $vars['elements']['#taxonomy_term']->bundle();
- $viewmode = $vars['elements']["#view_mode"];
- $suggestions[] = $original.'__'.$bundle.'__'.$viewmode;
- // dsm($suggestions);
- }
- function materiotheme_theme_suggestions_field_alter(&$suggestions, &$vars){
- if($vars['element']["#entity_type"] === "commerce_product_variation"
- && $vars['element']["#bundle"] === "materio_product_variation_type"
- && $vars['element']["#field_name"] === "title"){
- $test = 'test';
- $original = $vars['theme_hook_original'];
- $entity_type = $vars['element']["#entity_type"];
- $bundle = $vars['element']["#bundle"];
- $field_name = $vars['element']["#field_name"];
- $viewmode = $vars['element']['#view_mode'];
- $suggestions[] = $original.'__'.$entity_type.'__'.$bundle.'__'.$field_name.'__'.$viewmode;
- }
- }
- /**
- * Prepares variables for product templates.
- *
- * Default template: commerce-product.html.twig.
- *
- * @param array $variables
- * An associative array containing:
- * - elements: An associative array containing rendered fields.
- * - attributes: HTML attributes for the containing element.
- */
- function materiotheme_preprocess_commerce_product(array &$variables) {
- $test="test";
- // remove the variation as we already display it via views
- if($variables['elements']['#view_mode'] === 'order_summary'
- || $variables['elements']['#view_mode'] === 'home_summary'){
- unset($variables['product']['variation_title']);
- unset($variables['product']['variation_field_description']);
- unset($variables['product']['variation_price']);
- unset($variables['product']['variation_field_multiple']);
- unset($variables['product']['variation_commerce_variation_cart_form']);
- }
- $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
- $variables['language'] = $language;
- }
- /**
- * Implements hook_theme_suggestions_commerce_product_variation().
- */
- // function materiotheme_theme_suggestions_commerce_product_variation_later(&$suggestions, &$vars) {
- // $test = 'test';
- // }
- function materiotheme_preprocess_printable(array &$variables) {
- $site_config = \Drupal::config('system.site');
- $variables['site_name'] = $site_config->get('name');
- $variables['slogan'] = $site_config->get('slogan');
- }
|