I am trying to have one tpl file per view mode inside a module folder. But I can't get drupal to pick up the right tpl file.  I have been trying solutions on these pages:     /**  * Implements hook_theme_registry_alter()  **/ function nwd_press_room_theme_registry_alter(&amp;$theme_registry) {     global $theme_key;     $mod_path = drupal_get_path('module', 'nwd_press_room');     $theme_registry_copy = $theme_registry;       // munge on a copy     _theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', $theme_key, $mod_path);     $theme_registry += array_diff_key($theme_registry_copy, $theme_registry);     $hooks = array('node');      foreach ($hooks as $h) {         if (!isset($theme_registry[$h]['theme paths'])) {                 $theme_registry[$h]['theme paths'] = array();         }         nwd_press_room_insert_after_first_element($theme_registry[$h]['theme paths'], $mod_path);     }      dpm($theme_registry);  }  /**  * Helper function for re-ordering arrays (needed by theme_registry_alter)  */ function nwd_press_room_insert_after_first_element(&amp;$a, $element) {      if(is_array($a)) {         $first_element = array_shift($a);         if ($first_element) {             array_unshift($a, $first_element, $element);         } else {             array_unshift($a, $element);         }     } }   Since I still want the tpl file to be overridable in the theme. Does anyone have an example that works?
120697
I'd like to provide template implementation in my module and allow themes to override it. Basically, I add a suggestion by this simplified code:  function attach_preprocess_node(&amp;$vars) {   $vars['theme_hook_suggestions'][] = 'node__test'; }   (I don't want to use hook_theme to add a new theme because I want to reuse preprocess node functions. The theme name are awkward but I don't want to write node_attach_% to avoid confusion with node type.)  Then I use hook_theme_registry_alter() to add module path:  function attach_theme_registry_alter(&amp;$theme_registry) {   $path = drupal_get_path('module', 'attach') . '/themes';   $theme_registry_copy = $theme_registry;   _theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', 'node', drupal_get_path('module', 'node'));   $theme_registry += array_diff_key($theme_registry_copy, $theme_registry);   if (!isset($theme_registry['node']['theme paths'])) {     $theme_registry['node']['theme paths'] = array();   }   if (!isset($theme_registry['node']['theme paths'])) {     $first_element = array_shift($theme_registry['node']['theme paths']);     if ($first_element) {       array_unshift($theme_registry['node']['theme paths'], $first_element, $path);     }     else {       array_unshift($theme_registry['node']['theme paths'], $path);     }   } }   However it does not work. That means: the file themes/node--super.tpl.php is not used. It is used only if I copied it to the theme folder.
64792
In Drupal 7, if we wanted to push code to our environments enabling modules, we would call  in hook_update_N(). We no longer have that in Drupal 8, so how do we programmatically enable modules? Do we use Drupal 8's Configuration Manager or hook_update_N()?  A diff on the exported configuration yields this:  +++ b/cim/sync/core.extension.yml @@ -10,6 +10,9 @@ module:    config: 0    contact: 0    contextual: 0 +  ctools: 0   So it seems the module is enabled via code using Configuration Manager. We're also working with the idea of this:  function mymodule_update_8003() {   $modules = array(     'ctools',   );   \Drupal::service('module_installer')-&gt;install($modules); }   What is the correct method?
80415
I need to get the node's view mode so that in the mymodule_page_attachments, I can add libraries conditionally if the node's view mode is set to full or default. I tried the following but not able to get the nodes view mode once I retrieve the$node` object.   How to get node's view mode in hook_page_attachments?  Here is what we tried:  function mymodule_page_attachments(array &amp;$attachments) {   $node = \Drupal::routeMatch()-&gt;getParameter('node');   if(is_object($node)) {      // we tried printing but that didn't result any view_mode field.       ksm($node);      // Goal     if($node['view_mode'] == 'full' or $node['view_mode'] == 'default') {        // proceed with my logic.      }   } }
46828
Basically, I'm trying to override some files of the Uncode theme. But this is not a theme-specific question: it can be applied to any theme. The Uncode theme has a custom dir 'partials' (/uncode/partials/) that contains some layout elements. On my child theme I created a 'partials' folder as well (my-child-theme/partials), but the inner files seem not to be overridden. Is it normal? WP docs say that any file of the same name should be overridable, but is seems that's not true. Am I doing something wrong?
13516
The Question:  In Drupal 8: How do I add a template override for a view block and have that twig file reside in a custom module - not my theme?  Further Information:  I have already created a custom module that creates a content type, imports data from an RSS feed and generates nodes into the content type it created.  The module also contains a view YML file so that the view for my content type is created when the module is installed.  The view only has one display which is a block.  I would like to create a template override for the block and house the template override within the module (rather than within my theme).  The template override does the following:   Adds the appropriate classes to the block Adds an image beside the block title when the title is displayed Wraps the {{ content }} in a div with an appropriate class Loads the custom module's library to apply CSS   The goal is to have a module that a non-technical person can install, assign a block to the desired region and have all the templates, CSS, JS, etc pull from the module.  I don't want them to have to copy a template into their theme, etc.  I want the block to be a view so that the user can use the Views UI to make any desired updates to the view block's fields, number of returns, etc.  I was able to get Drupal to recognize the template by using hook_theme_registry_alter() but the variables from the block are null.  Both the {{ label }} and {{ content }} are null when I kint them in the template override.  Here is the hook_theme_registry_alter() code:  /**  * Implements hook theme_registry_alter  **/ function MYMODULE_theme_registry_alter(&amp;$theme_registry){   $theme_registry['block__views_block__MYVIEW_block_1']['path'] = drupal_get_path('module','MYMODULE') . '/templates/';   $theme_registry['block__views_block__MYVIEW_block_1']['template'] = 'block--views-block--MYVIEW-block-1'; }   It should be noted that when I used hook_theme_registry_alter() for a view page template override in my module it worked.  My guess is that the variables were pulled from the page alias.  Please include detailed information because I am still learning about the various hooks and how variables are passed.  Thanks in advance!
54856
When "themeing" modules, especially core modules, as far as I know it is a good idea to take the module specific tpl.php files, duplicate the ones you need, and modify them once they're in the relevant theme directory.  However, what if I want to modify a .inc file? Is it the same process as with tpl.php files, or is there a better workflow? Basically what I would like to do is change some of the user status messages found in user.admin.inc in the core Drupal 7 User module. I'm not sure if editing this file directly is a good idea. Thoughts?
96354
I am using the  base theme, and am trying to override page.tpl.php.    This file is in the base theme in sites/all/themes/omega/templates/system.  When I copy it into my theme, edit it, clear caches, I don't see my changes?  Why can't I override this template?
43041
My problem is that depending on a running mode my Drupal website might have either regular permalinks, or pretty, aliased ones. And "Page specific visibility settings" for blocks on specific pages (Show on only the listed pages) do not work across the modes.  It would be logical if let's say: node/23 syntax could work in any case, but it seems that it doesn't.  Do I have to change every setting for every block every time I switch permalink structure? Or there is more flexible solution to this?
56577
In my Drupal7, I have same piece of code in tpl.php files for two different nodes. My tpl.php files are following:  page--node--9.tpl.php page--node--11.tpl.php   Since code is same for both pages, it is possible to create a tpl.php file for both nodes? I mean something like   page--node--9and11.tpl.php
39084
In Drupal 7, I can use drupal_add_js within a theme's template.php file as a theme_preprocess_html(&amp;$vars) function:     drupal_add_js(drupal_get_path('theme', 'mytheme') . '/js/scripts.js',         array(           'group' =&gt; JS_THEME,           'preprocess' =&gt; TRUE,           'weight' =&gt; '999',         ));    $vars['scripts'] = drupal_get_js();   In Drupal 8, I've tried converting this using attached in my theme's .theme file as such:    $vars['#attached']['js'] = array(     array(       'data' =&gt; drupal_get_path('theme', 'mytheme') . '/js/scripts.js',       'options' =&gt; array(         'group' =&gt; JS_THEME,         'preprocess' =&gt; TRUE,         'every_page' =&gt; TRUE,       ),     ),   );   ... but that did not work and there were no errors in watchdog / console or otherwise.  According to the  for drupal_add_js:     Deprecated - as of Drupal 8.0. Use the #attached key in render arrays   instead.   There was not much more info that that however. It seems that drupal_add_css will also use this method. I know it's still early days for Drupal 8 but I was hoping to get a jump on this.
82099
I'm currently using the preprocess_breadcrumb hook in my .theme file to customize the output of my breadcrumbs like so:  function mytheme_preprocess_breadcrumb(&amp;$variables){     $node = \Drupal::routeMatch()-&gt;getParameter('node');     $current_path = \Drupal::service('path.current')-&gt;getPath();     $result = \Drupal::service('path.alias_manager')-&gt;getAliasByPath($current_path);     $crumbs = explode("/", $result);     if($node){         $variables['current_title'] = $node-&gt;getTitle();         $variables['crumbs'] = $crumbs;     } }   I then use breadcrumb.html.twig to use these new variables like so      &lt;nav role="navigation" aria-labelledby="system-breadcrumb"&gt;     &lt;h2 id="system-breadcrumb" class="visually-hidden"&gt;{{ 'You are here'|t }}&lt;/h2&gt;     &lt;ul class="breadcrumbs"&gt;         {% for crumb in crumbs %}              {% if loop.first %}         &lt;li&gt;&lt;a href="./"&gt;Home&lt;/a&gt;&lt;/li&gt;         {% elseif loop.last %}         &lt;li class="current"&gt;&lt;a href="#"&gt;{{ current_title }}&lt;/a&gt;&lt;/li&gt;          {% elseif crumb == 'node' %}         {% else %}         &lt;li&gt; &lt;a href="../{{ crumb }}"&gt;{{ crumb }}&lt;/a&gt;&lt;/li&gt;         {% endif %}         {% endfor %}     &lt;/ul&gt; &lt;/nav&gt; {% endif %}   However I'd like it more if all this was encapsulated in a module. In mymodule.module file I have  function mymodule_preprocess_breadcrumb(&amp;$variables){ $node = \Drupal::routeMatch()-&gt;getParameter('node'); $current_path = \Drupal::service('path.current')-&gt;getPath(); $result = \Drupal::service('path.alias_manager')-&gt;getAliasByPath($current_path); $crumbs = explode("/", $result); if($node){     $variables['current_title'] = $node-&gt;getTitle();     $variables['crumbs'] = $crumbs; }   }  But this function never fires. Is there a way to use the preprocess_breadcrumb hook from a module?
103846
As you know default wrapper for menu item in Drupal 7 can be modified via function theme_menu_link().  by overriding   theme_menu_link($variables) {}    function we can modify the rendered html output of menu link but it will change all of menu items that their #theme attribute is set to this function. for example in main menu, each item has menu_link__main_menu value in it's #theme attribute.  Now I want to create a custom wrapper function in my theme.  I searched and I found I must create a function with structure like  theme_menu_link($variables) {}   and also I must REGISTER the function name in my theme.  For registration, I used function theme_theme() {}  function theme_theme() {return array('custom_menu_item_wrapper' =&gt; array());}   ** theme is replaced by name of theme ** custom_menu_item_wrapper is the name of my function for wrapping operation  But I don't know, how should I define parameters in theme function registration because when custom_menu_item_wrapper($variables) function is called $variables is NULL
42684
I know there is a question  but I checked its answers and it didn't help. I'm just learning developing modules for Drupal so maybe it's something really stupid but I have no idea...  My hook (in testModule4.install):  function testModule4_update_7001() {  $schema['testModule4_table'] = array(     'description' =&gt; 'TODO: Description',     'fields' =&gt; array(         'main_id' =&gt; array(             'description' =&gt; 'TODO: Description.',             'type' =&gt; 'serial',             'not null' =&gt; TRUE,         ),         'settings' =&gt; array(             'description' =&gt; 'TODO: Description',             'type' =&gt; 'text',             'not null' =&gt; FALSE,         ),         'uid' =&gt; array(             'description' =&gt; 'TODO: Description',             'type' =&gt; 'int',             'not null' =&gt; FALSE,         ),         'created' =&gt; array(             'description' =&gt; 'TODO: Description',             'type' =&gt; 'int',             'not null' =&gt; FALSE,         ),         'changed' =&gt; array(             'description' =&gt; 'TODO: Description',             'type' =&gt; 'int',             'not null' =&gt; FALSE,         ),     ),     'primary key' =&gt; array('main_id'), );  db_create_table('testModule4_table', $schema['testModule4_table']);  }   My module is working just fine. The schema_version of module in database is 0 but update.php just cannot see it. What can be the cause of that? :/ I was trying clearing cache and reenabling a module but without success. I just don't know where to search for source of the problem. If you need more data, just comment :/ .  Edit:  I created simple module:  testModule.module:  &lt;?php   function testModule_myform($delta = "") {      $form['something'] = array(         '#type' =&gt; 'markup',         '#markup' =&gt; 'Something',     );     return $form; }    /**  * Implements hook_menu();  */  function testModule_menu() {     $items["test/test"] = array(         'title' =&gt; 'testModule',         'description' =&gt; 'TODO: Description',         'page callback' =&gt; 'drupal_get_form',         'page arguments' =&gt; array('testModule_myform'),         'access callback' =&gt; TRUE,      );     return $items; }   testModule.info:  name = testModule description = Test module for Drupal experiments. package = CustomTest core = 7.x   testModule.install:  function testModule_update_7001() {     drupal_set_message('It works!');     print 'Show something!'; }   And it still ignores this hook... Is it officially a Drupal bug and I need to reinstall the whole Drupal? >_&lt;
48930
I read about Drupal behaviors today, and I tried writing the following code.  (function ($) {    Drupal.behaviors.mymodule = {     attach: function (context, settings) {       $('#mymodule_id', context).change(function () {         alert('Handler for .change() called.');       });     }   };  }(jQuery));    Is Drupal.behaviors.mymodule the namespace? What are the context and settings parameters passed to the Drupal behavior? Is this the equivalent of document.ready()?   Can I attach any number of functions?  Can I define JavaScript functions which will be called somewhere?
84632
I have a third party php library which I would like to use in a module. How do I do that in Drupal 8? In drupal 7, I have done things like the following code, but libraries_get_path() doesn't exist in Drupal 8, and I'm not exactly sure how things change, not that we use namespaces (of which I am a beginner).  require(libraries_get_path('twitter-api-php') . '/TwitterAPIExchange.php');   And, where should I place my library? Should I create a new libraries directory and put it in the root, just like modules and themes are now in the root?
54857
I want to generate the html elements and their classes to fit my styling of the main menu.    I'm confused by all the near-possibilities offered in the api documentation and by looking at core themes etc. and still can't quite see what I have to do, or where I have to do it. I would be very grateful for clear pointers to:     which php functions I have to write;  which variables I need to add / update;  in which files the functions will go.   Presumably, in MYTHEME.theme I will need a preprocess function of some sort to add to the attributes and item.attributes variables that links.html.twig uses to print the menu ul and the menu item li's.   [Update] So far I have discovered one way to place classes on the Main Menu's ul but ideally I would like to add a class to each submenu's ul indicating the depth of the sub-menu. And I cannot locate any documentation or examples from which I can understand the generation / modifying of the main menu's individual link items.    This function goes into the file  MYTHEME.theme.  function MYTHEME_preprocess_page(&amp;$variables) {    // Pass the main menu and secondary menu to the template as render arrays.   if (!empty($variables['main_menu'])) {     $variables['main_menu']['#attributes']['id'] = 'main-menu-links';     $variables['main_menu']['#attributes']['class'] = array('links', 'clearfix', 'MYNEW_class');   }  }
121595
I work in D8, I create a custom module first_module. By modules create a url and display all nodes by *.html.twig file.  Write code in controller.php  public function contentthree() {    $connection = Database::getConnection();    $query = $connection-&gt;select('node', 'n');   $query-&gt;fields('n', ['nid', 'type']);    $groups = $query-&gt;execute()-&gt;fetchAll();    foreach ($groups as $group) {     $events[] = [$group-&gt;nid, $group-&gt;type];   }    return [     '#theme'  =&gt; 'first_module_display',     '#events' =&gt; $events,   ]; }   In *.module  function first_module_theme($existing, $type, $theme, $path) {    return [     'first_module_display' =&gt; [       'variables' =&gt; ['events' =&gt; NULL],       'template'  =&gt; 'first-module-list',     ],   ]; }  function _get_node_details() {    $output = 'Welcome D8';    $output .= 'Node Details';    return $output; }   and create templates first-module-list.html.twig and display data  {%for key, data in events %}  {%for key1, data1 in data %}     {{ data1 }}  {% endfor %}  {% endfor %}   work fine and showing data correct. But, my question is how to call function _get_node_details() and how to render node details in first-module-list.html.twig files?