I recently had a Drupal core patch that I needed to use on a site I’m building. This can be done manually using the patch
command, but when managing a Drupal project with Composer, any manual patches could get wiped out on the next run of the composer update
or composer install
commands. In order to make sure patches stick, they need to be added to Composer, like a requirement.
Tag: Drupal
Permissions Error When Pulling Changes for Drupal
Lately, when using a git pull
to update a Drupal project, I’ve been running into this error:
error: unable to unlink old 'sites/default/default.settings.php' (Permission denied)
Continue reading Permissions Error When Pulling Changes for Drupal
Bootstrap 3 Form Styles in Drupal 8
I’m slowly moving along on my first Drupal 8 project. After getting annoyed enough with the look of the login form, I decided to update my form templates to use Bootstrap 3 styles.
Accessing Drupal Site Name and Menus in Templates
When I am creating a custom Drupal site, I like to hard code a few things into the templates, such as the site name and menus. This prevents the client from doing something like accidentally moving the menu blocks into a different region, and it also gives me more control over the HTML markup.
In Drupal 7, there are two ways that I have found to access this system data within the templates. I am going to walk through an example of each method in which I will add the following elements to my page.tpl.php
template file:
- My site name
- The main menu
- A custom menu named “Secondary menu” (which has a machine name of “menu-secondary-menu”)
Method 1
The first method involves setting up some variables in the template.php
file and then accessing those variables in the page.tpl.php
file.
In the template.php
file:
function newhopeks_preprocess_page(&$variables) {
$variables['site_name'] = filter_xss_admin(variable_get('site_name', 'Default Site Name'));
$variables['main_menu'] = menu_main_menu();
$variables['secondary_menu'] = menu_navigation_links('menu-secondary-menu');
}
In the page.tpl.php
file:
<h1><?php print $site_name; ?></h1>
<?php
print theme('links__system_main_menu', array('links' => $main_menu));
print theme('links__menu_secondary_menu', array('links' => $secondary_menu));
?>
Method 2
The second method bypasses the template.php
file and accesses the data directly.
In the page.tpl.php
file:
<h1><?php print filter_xss_admin(variable_get('site_name', 'Default Site Name')); ?></h1>
<?php
print theme('links__system_main_menu', array('links' => menu_main_menu()));
print theme('links__menu_secondary_menu', array('links' => menu_navigation_links('menu-secondary-menu')));
?>