How to create an anchor link per node in Drupal views

Standaard

Creating anchor links in views in Drupal can be very easy. You can to it this way:

  • In the view render the output as fields.
  • Add the field ‘Content: path’.
  • Open the fieldset ‘Rewrite results’.
  • Check the rewrite output checkbox.
  • Enter the following text in the rewrite output textarea:
    • <a href='[path]#youranchor’>Your custom link text</a>

The [path] token is the path alias of the node and can be found in the replace patterns section.

Advertenties

How to get the full taxonomy term level path in the url with autopath in Drupal 7.

Standaard

If you want to show all levels of the taxonomy term in the path, you can simply enter the following to your taxonomy url pattern in admin/config/search/path/patterns

[term:parents:join:/]/[term:name]

Does your Drupal views combine filter appears to be case sensitive?

Standaard

It seems to be an issue with MySQL wich is possible to ignore by adding the following code. Just create a module and add a hook_views_query_alter in your module:

function yourmodulename_views_query_alter(&$view, &$query) {
  // Find all combine fields and make them case insensitive.
  foreach ($query->where as $group_key => $group) {
    foreach ($group['conditions'] as $key => $condition) {

          if (is_string($condition[‘field’]) && (preg_match(‘/:views_combine/’, $condition[‘field’]))) {

            $query->where[$group_key][‘conditions’][$key][‘field’] = $condition[‘field’] . ‘ COLLATE utf8_general_ci’;
        }
    }
  }
}

More info can be found on:

https://drupal.org/comment/7998079#comment-7998079

How to solve the drush message ‘Directory …drush/cache/default exists, but is not writable. Please check directory permissions.’?

Standaard

In the OSX execute the following command:

chown -R $USER ~/.drush

In case you receive the following message:
chown: ….drush/cache/default: Operation not permitted

Then execute the command again, but with sudo:

sudo chown -R $USER ~/.drush

More info can be found on https://drupal.org/node/1488682

How to modify a view title in Drupal when the view returns no result

Standaard

It is possible to check in a view if the no results behaviour is activated. You can do this by checking the $view->result array in the hook_views_pre_render.


/**
* hook_views_pre_render
*
* @param type $view
*/
function one_agency_views_pre_render(&$view) {
// This view contains a no results behaviour
// In case no results behaviour is activated, we need to change the title
if ($view->name == 'your_view_name' && $view->current_display == 'your_view_display_name') {
if (count($view->result) == 0) {
$view->build_info['title'] = "The title for the no results behaviour";
}
}
}

How to delete a content type field programmaticaly in Drupal

Standaard

Delete a field within a content type
// Get the field instance object for a particular content type
$field = field_info_instance('node', 'your-field-name', 'content-type-machine-name');
// And delete it
field_delete_instance($field);

Delete all instances of a field
// Get the field instance object
$field = field_info_field(‘your-field-name’);
// And delete all instances of this field
field_delete_field($field);