How to make block with list of terms from blog postings I would like to display a navigational block in a sidebar on a single-user blog page which will have a listing of all taxonomy terms used in the blog entries.

I am using a custom content type and Views to make the blog. I have set up a vocab for this content type, with multiple terms from this vocab selectable for each posting.

I set up a block display in the view with a field using Taxonomy: All terms. Then a filter limited to my specific vocab. Everything is fine, except that I am getting duplicate terms in the list, as some blog entries have the same terms.

Can anyone please tell me how to remove the duplicate results, or tell me a better way to get what I want?

It sounds as if you have created a view of nodes, and using the Taxonomy: All terms field to display the terms of those nodes. That approach will indeed produce duplicate results.

Instead, you need to create a view of Taxonomy Terms. I don't know which versions you are using, but here is the export of such a View made with Drupal 7  & Views 7.x-3.0-rc1.

$view = new view;
$view->name = 'tags';
$view->description = '';
$view->tag = '';
$view->base_table = 'taxonomy_term_data';
$view->human_name = 'Tags';
$view->core = 7;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Tags';
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Taxonomy term: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'taxonomy_term_data';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
$handler->display->display_options['fields']['name']['link_to_taxonomy'] = 1;
/* Sort criterion: Taxonomy term: Name */
$handler->display->display_options['sorts']['name']['id'] = 'name';
$handler->display->display_options['sorts']['name']['table'] = 'taxonomy_term_data';
$handler->display->display_options['sorts']['name']['field'] = 'name';
/* Filter criterion: Taxonomy vocabulary: Machine name */
$handler->display->display_options['filters']['machine_name']['id'] = 'machine_name';
$handler->display->display_options['filters']['machine_name']['table'] = 'taxonomy_vocabulary';
$handler->display->display_options['filters']['machine_name']['field'] = 'machine_name';
$handler->display->display_options['filters']['machine_name']['value'] = array(
  'tags' => 'tags',
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'tags';


How to create a drop down menu for monthly archives? I'd like to be able to display a block on the right sidebar with a drop-down menu for the monthly archives ("blog post" content type). Exactly as shown in the following screenshot taken from http://curbed.com/

Can anybody please advise me on how to do this with Drupal 7? Thanks!

I have create a new content type name with blog which have default fields(node title and body) Steps are given below.

First create a view(jump menu) for monthly archive.

Select post date of node one for drop-down text and second for link. All settings are given in screenshot.

Settings for jump menu

Settings for post date(first)

Settings for post date(Second)

Now add a page where display list of node based on drop-down value selection

Follow Page settings

Contextual filter settings for year

Contextual filter settings for year

Select a region for your monthly archive block. Here I am adding views export code that will help you better.

Views export code

$view = new view();
$view->name = 'monthly_archives';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Monthly Archives';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Monthly Archives';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'none';
$handler->display->display_options['style_plugin'] = 'jump_menu';
$handler->display->display_options['style_options']['hide'] = TRUE;
$handler->display->display_options['style_options']['path'] = 'created_1';
$handler->display->display_options['style_options']['choose'] = 'Select Month';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'blog' => 'blog',
);

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'jump_menu';
$handler->display->display_options['style_options']['hide'] = TRUE;
$handler->display->display_options['style_options']['path'] = 'created_1';
$handler->display->display_options['style_options']['choose'] = 'Select Month';
$handler->display->display_options['style_options']['default_value'] = TRUE;
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Post date */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'node';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['label'] = '';
$handler->display->display_options['fields']['created']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['created']['alter']['text'] = '[created]';
$handler->display->display_options['fields']['created']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['created']['date_format'] = 'custom';
$handler->display->display_options['fields']['created']['custom_date_format'] = 'F Y';
/* Field: Content: Post date */
$handler->display->display_options['fields']['created_1']['id'] = 'created_1';
$handler->display->display_options['fields']['created_1']['table'] = 'node';
$handler->display->display_options['fields']['created_1']['field'] = 'created';
$handler->display->display_options['fields']['created_1']['label'] = 'link path';
$handler->display->display_options['fields']['created_1']['exclude'] = TRUE;
$handler->display->display_options['fields']['created_1']['alter']['alter_text'] = TRUE;
$handler->display->display_options['fields']['created_1']['alter']['text'] = 'archive/[created_1]';
$handler->display->display_options['fields']['created_1']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['created_1']['date_format'] = 'custom';
$handler->display->display_options['fields']['created_1']['custom_date_format'] = 'Y/m';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['title'] = 'Monthly Archives';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
$handler->display->display_options['defaults']['row_options'] = FALSE;
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Field: Content: Body */
$handler->display->display_options['fields']['body']['id'] = 'body';
$handler->display->display_options['fields']['body']['table'] = 'field_data_body';
$handler->display->display_options['fields']['body']['field'] = 'body';
$handler->display->display_options['fields']['body']['label'] = '';
$handler->display->display_options['fields']['body']['element_label_colon'] = FALSE;
$handler->display->display_options['defaults']['arguments'] = FALSE;
/* Contextual filter: Content: Created year */
$handler->display->display_options['arguments']['created_year']['id'] = 'created_year';
$handler->display->display_options['arguments']['created_year']['table'] = 'node';
$handler->display->display_options['arguments']['created_year']['field'] = 'created_year';
$handler->display->display_options['arguments']['created_year']['default_action'] = 'default';
$handler->display->display_options['arguments']['created_year']['default_argument_type'] = 'raw';
$handler->display->display_options['arguments']['created_year']['default_argument_options']['index'] = '1';
$handler->display->display_options['arguments']['created_year']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['created_year']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['created_year']['summary_options']['items_per_page'] = '25';
/* Contextual filter: Content: Created month */
$handler->display->display_options['arguments']['created_month']['id'] = 'created_month';
$handler->display->display_options['arguments']['created_month']['table'] = 'node';
$handler->display->display_options['arguments']['created_month']['field'] = 'created_month';
$handler->display->display_options['arguments']['created_month']['default_action'] = 'default';
$handler->display->display_options['arguments']['created_month']['default_argument_type'] = 'raw';
$handler->display->display_options['arguments']['created_month']['default_argument_options']['index'] = '0';
$handler->display->display_options['arguments']['created_month']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['created_month']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['created_month']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['path'] = 'archive/%/%';


Exclude a JavaScript file from a node I'd like to exclude a js file from loading on to a specific node.

Right now my libraries.yml file looks like this:

global-styling:
  version: 1.x
  css:
    theme:
      css/bootstrap/bootstrap.css: {}
      css/style2.css: {}
      css/header.css: {}
      css/color-1.css: {}
      css/themify-icons.css: {}
      css/jquery-ui.css: {}
  js:
    js/bootstrap.js: {}
    js/jquery-ui.js: {}
    js/popper.js: {}
    js/tooltip.js: {}
    js/wow.min.js: {}
    plugin/appear/jquery.appear.js: {}
    js/custom.js: {}
  dependencies:
    - core/jquery

I'd like to exclude the js/custom.js from loading on node/4. Alternatively I would like to load that file ONLY for the front page.

Delete/Exclude js/custom.js from the global-styling section in THEMENAME.libraries.yml and define it as a library at the end of the same file

# THEMENAME.libraries.yml
custom-js:
  version: 1.x
  js:
    js/custom.js: {}
  dependencies:
    - core/jquery

And then include the library conditionally to where you want it using THEMENAME_preprocess_page function in THEMENAME.theme

//THEMENAME.theme
function THEMENAME_preprocess_page(&$variables) {

    //include it if its front_page
    if ($variables['is_front'] == TRUE) {
        $variables['#attached']['library'][] = 'THEMENAME/custom-js';
    }

    //include it if its NOT node 4
    $node = \Drupal::routeMatch()->getParameter('node');
    if ($node instanceof \Drupal\node\NodeInterface && $node->id() != 4) {
        $variables['#attached']['library'][] = 'THEMENAME/custom-js';
    }
}

For more info read the docs


Which graphs solution for Drupal 7 can be used to upgrade my Open Flash Chart solution from Drupal 6? I have upgraded from Drupal 6 to Drupal 7 and for me, everything is better in Drupal 7 until I hit this problem.

What I'm trying to achieve:

I have to create and show graphs to users depending on whatever the data they have stored on the site, I mean I have collected the data and stored in a Mysql database. I now have to fetch these data from that Mysql database and display it as a neat graph.

In drupal 6, making such dynamic graph is a cake walk..! I used Charts and graphs module with "Open Flash Chart" to create some very interactive and pretty graphs. But it does not has a Drupal 7 version..!

Attempting to use the 'Charts' module fails:

Then I searched for one that could work in D7 and found the charts module. It looked very promising and has a Drupal 7 version too. So I tried to install it, but I can simply not get it to work! I found a patch, but still no luck. Even if I get it to work, it will only work with Google Charts and not with Open Flash Charts or Fusion Charts because it requires those charts to be installed by us and Open Flash Charts or Fusion Charts, do not have a D7 version..!! FYI, the same problem existed in D6: when I installed everything (even Open Flash Chart API), it said "no chart plugin installed". And not even a single line of documentation is provided regarding how to install these plugins and make other charts work. Hence I think its out of the picture.

My Question(s): So what can I do now..?? How can I create graphs..? What can I use..??

Update about this question:

Since I didn't find any graphs module that I could use in my Drupal 7 site, I tried using an external PHP charting library "pChart". I configured everything without getting any errors or warnings, but I only get a bizarre output ...

I have explained everything in detail, along with the code I have used to create the graph in my (new) question What is causing the unusual output when trying to create charts in Drupal 7 using the pChart library? Any help to answer that new question would be greatly appreciated!

I've used highcharts script before, not with this module, but it might work for you http://drupal.org/project/highcharts


Pass info from page link to form I am trying to build a custom module that uses a theme page to display a list of items withing a table. Each item has a unique ID. and I would like to have links within this table so that my users can preform actions using the uid. The link works and takes you to the form but it doesn't carry over the uid.

Here is the code from my theme file.

<?php

/**
 * @file
 * definition of uc-bitcoin-account-outgoing-escrows.tpl.php.
 */
$user = user_load($variables['uid']);

global $base_url;

$transactions = db_query("SELECT * FROM {uc_btc_escrow_payment} WHERE from_account='$user->uid'");

$header = array(t('Escrow ID'), t('Amount'), t('Payment'), t('Allocated to'), t('Release'), t('Dispiute'), t('Date'));

$rows = array();

foreach ($transactions as $transaction) {
  $rows[] = array(
      $transaction->escrow_id, $transaction->amount, $transaction->status , $transaction->to_user, 'escrow_id . '">Release Payment', 'escrow_id . '">Dispute Payment', date('d/m/Y   g:i:s A', $transaction->created)
  );
}

print t('
Outgoing Escrows
');

print theme('table', array('header' => $header, 'rows' => $rows));
?>

When the user clicks on the Release Payment link it will take them to the form I created but it has a few errors. And Doesn't work. Here is the code for that function.

function uc_escrow_release_payment($form, &$form_state, $escrow_id) {

  $form['#$escrow_id'] = $escrow_id;

  $transaction = db_query("SELECT * FROM {uc_btc_escrow_payment} WHERE escrow_id= :escrow_id", array(':escrow_id' => $escrow_id))->fetchAssoc();

  $user = user_load($transaction['reference']);
  $to_user = $transaction->to_user;
  return confirm_form($form, check_plain('Release Escrow Payment?'), 'user/orders', check_plain('Are you sure you want to release this payment and send the funds to ' . $to_user . '?'), check_plain('Yes'));
}

The errors I am getting are because the information isn't getting passed from one page to the other.

Notice: Undefined index: reference in uc_escrow_release_payment()
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load()
Notice: Trying to get property of non-object in uc_escrow_release_payment()

I think I am missing something small. Thank you for the help.

I thought it easier if I just mark up the code a bit, I've tried to notate where I made changes.  Can you run this and tell us what it does, if it doesn't solve your problem?

<?php

  /**
   * @file
   * definition of uc-bitcoin-account-outgoing-escrows.tpl.php.
   */

  /** clr use $account instead of $user in case global $user is already in scope **/
  $account = user_load($variables['uid']);
  /* also, loading the user seems extraneous if you're not checking
   * anything else (is user valid, is user in a certain role, etc.)
   * if so, you should include an additional check.  If not, just
   *  do your query using $variables['uid']
   */
  global $base_url;

  /** clr drupalized the query **/
  $transactions = db_query("SELECT * FROM {uc_btc_escrow_payment} WHERE from_account=:user_id", array(':user_id' => $account->uid));

  $header = array(t('Escrow ID'), t('Amount'), t('Payment'), t('Allocated to'), t('Release'), t('Dispiute'), t('Date'));

  $rows = array();

  /** clr adding a check here **/
  if (!$transactions) {
    die('No Transactions were found');
  }
  /** clr clean up the anchor tags **/
  foreach ($transactions as $transaction) {
    $release_href = $base_url . '/user/orders/release-escrow/' . $transaction->escrow_id;
    $dispute_href = $base_url . '/user/funds/dispute-escrow/' . $transaction->escrow_id;
  $rows[] = array(
    $transaction->escrow_id,
    $transaction->amount, $transaction->status , $transaction->to_user,
    l('Release Payment', $release_href),
    l('Dispute Payment', $dispute_href),
    date('d/m/Y   g:i:s A', $transaction->created)
  );
}

print t('
Outgoing Escrows
');

print theme('table', array('header' => $header, 'rows' => $rows));
?>

And then your function:

function uc_escrow_release_payment($form, &$form_state, $escrow_id) {

/** check $escrow_id **/
if (!$escrow_id || $escrow_id == '') {
  die('Do something here, because you don\'t have everything you need');
}

/** clr not sure why '$' is used in $form key? */
$form['#$escrow_id'] = $escrow_id;

/** clr changed to fetch object **/
$transaction = db_query("SELECT * FROM {uc_btc_escrow_payment} WHERE escrow_id=:escrow_id", array(':escrow_id' => $escrow_id))->fetchObject();
/** check transaction **/
if (!$transaction) {
  die('No transaction was found; In ' . __FUNCTION__);
}
/** clr don't use $user for same reason above **/
$account = user_load($transaction->reference);
$to_user = $transaction->to_user;
/** check_plain() is only necessary when you're dealing with user supplied text.
 *  that being said, I guess it never hurt to be over cautios */
return confirm_form($form, check_plain('Release Escrow Payment?'), 'user/orders', check_plain('Are you sure you want to release this payment and send the funds to ' . $to_user . '?'), check_plain('Yes'));
}


Make a direct database query Basically I want to run this query against the current database and retrieve all node titles with node type of foo_type.

SELECT title FROM node WHERE type='foo_type' ORDER BY title ASC

How can I do this using db_query or any similar function? I tried doing the below but $result is empty.

$result = db_query("SELECT title FROM node WHERE type='foo_type' ORDER BY title ASC");

Please note any D6 and D7 differences if there are any.

For Drupal 6:

$result = db_query("SELECT title FROM node WHERE type = '%s' ORDER BY title ASC", 'foo_type');
$titles = array();
while ($row = db_fetch_object($result)) {
  $titles[] = $row->title;
}

For Drupal 7 you have a bunch of options

Static:

$args = array(':type' => 'foo_type');
$titles = db_query("SELECT title FROM node WHERE type = :type ORDER BY title ASC", $args)->fetchCol();

Dynamic:

$titles = db_select('node')
  ->fields('node', array('title'))
  ->condition('type', 'foo_type')
  ->orderBy('title')
  ->execute()
  ->fetchCol();

And a couple of less-direct methods...

EntityFieldQuery:

$query = new \EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('type', 'foo_type')
  ->propertyOrderBy('title');

$results = $query->execute();
if (!empty($results['node'])) {
  $nodes = node_load_multiple(array_keys($results['node']));
  $titles = array_map(function($x) { return $x->title; }, $nodes);
}

API (deprecated):

$nodes = entity_load('node', FALSE, array('type' => 'foo_type'));
$titles = array_map(function($x) { return $x->title; }, $nodes);


Behavior for #datepicker onselect not working i have a datepicker in a webform. I want to be notified when a date is selected in the datepicker. In my form template i drupal_add_js a js starting with :

Drupal.behaviors.booking_form_tma = {
    attach: function (context, settings) {
        for (var id in Drupal.settings.date_popup) {
            alert('found');
            var datepicker_settings = Drupal.settings.date_popup[id].settings;
            datepicker_settings.onSelect = function(dataText) {
                alert('selected: ' + dataText);
            };
            $('#' + id).datepicker(datepicker_settings);
        }
    }
};

The behavior attach code gets called only once, after the page gets loaded and never reach the alert: i guess the datepicker is not present in the div at this time. When the datepicker icon is clicked, the datepicker gets injected in a div but the behavior is not called and so nothing happen. None of the alert in the code above are shown.

Why doesn't it work?

jQuery(document).ready(function() {
    jQuery(".datepicker").datepicker({
        showOn: "button",
        buttonImage: "/images/calander.png",
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true,
        maxDate:'0',
        onSelect: function (selectedDateTime){
                //alert("here");
            }
    });
 });

you can also write above code in js file


Node language in views contextual filters I have a multi-lingual site. On the article page has a block with other articles. How to bring in the article section with the same language as the current node? Interested in is the use of contextual filters. Option of using the language of the current user filter is not suitable.

Why isn't the current users language suitable, that's what you want

Have you looked in the filters section of views (Bottom left of the views editing screen) rather than contextual filters? There should be the current users language as a filtering option in there.


Dynamic locations in page content My company website has several physical locations / branches that need to be referenced all throughout the website on basic pages.

I would like to create one central table with one instance of each location so that when details change for that location I can make that one change and it will dynamically update all instances of that location across the site.

I could create a block for each location and reference that block where applicable, but the location content needs to go within the actual body of the pages and not in a block region. Is this possible?

You could try something like the following:

Custom content type 'location' with the fields you need for your locations
Consider addressfield if these are address locations, or geofield if not
if you need mapping, consider leaflet
To use/display these locations elsewhere, you could add an entity reference field to other nodes or entities, and populate the field with links to the required location(s).
if you need to embed locations (e.g. in the body of a node ) perhaps node embed or advanced entity token (I've not used either one)
If you need to add additional view modes, you can use display suite or entity_view_mode

So, the general idea is that you define locations as needed using a custom content type. Then you attach these locations to other nodes/entities using fields or by embedding using a module that uses tokens or another special syntax.

With either approach, each location is stored just once, and the location is rendered on a page using a view mode that makes sense in that particular context.

To address your question about blocks specifically: you could indeed create blocks for company locations. To associate these blocks to pages/nodes, you could either embed the block in a node with something like insert block (https://drupal.org/project/insert_block), or attach the block to a node using block reference (https://drupal.org/project/blockreference).


How to alter commerce cart view to show custom line item data - either through UI or custom module In a custom module I am adding data to a line item added to the cart like this:

$user_to_add =_get_user_by_ain($ain);
$product = commerce_product_load($product_id);
$line_item = commerce_product_line_item_new($product, 1, 0, array('apply_to_user' => $user_to_add));
commerce_cart_product_add($user->uid, $line_item);

This data is used in Rules after checkout is completed.  What I'm struggling with now is being able to show that data in the cart view (default, Commerce provided, commerce_cart_form).  For example, if the $user_to_add contains the users first name, I'd like to be able to show that in the cart view next to the product label.

I've been going through the views api, testing the hooks available, and I can't figure out where to do this.  In the hooks that I've tried, the data is is available in $view->result[0]->_field_data['commerce_line_item_field_data_commerce_line_items_line_item_]['entity']->data['apply_to_user']

If you're wanting to display information from inside the $order->data array, then you'll need to create a Views handler for each value and write some code to load the object, access the data, and then display it. An example of how to do this can be found in the GetID3 views integration. It loads file metadata and exposes it to views, but the idea is the same.


How do I view the author of a comment in a view block? I want to create a view block to display information about the author of a comment.

So I created a comment block and added the fields I missed.
My problem, what contextual filter does it need to be added to show only the author of the comment and not all the authors ?

In response to 4K4 :

To place a view block next to each comment use the module:

EVA: Entity Views Attachment

Create a new View for user, add an EVA display, connect it in ENTITY CONTENT SETTINGS to the Entity Type comment, the Bundle default comment and as Arguments provide the token for the user id [comment:author:uid]. Add a contextual filter for the User ID.

Now the EVA views block appears in the Comment Type and you can place it in Manage Display.

You can also use as Argument the comment id and connect it to the View you have in the question which is based on comments and has the author as relationship.


add a class to page depending on order total (Drupal Commerce)? I want to add a  class to a page when the order total reaches a certain level.

I came up with this piece of code, which seems to work:

function class_price_preprocess_html(&$variables){
  global $user;
  $order = commerce_cart_order_load($user->uid);
  if ($order) {
    $wrapper = entity_metadata_wrapper('commerce_order', $order);
    $line_items = $wrapper->commerce_line_items;
    $total = commerce_line_items_total($line_items);
    if($total['amount']>5000){
        $variables['classes_array'][] = "class-pr";
    }
  }
}


PECL uploadprogress installed - but no progress bar, just spinning gif Pretty much same question as this.  I've set everything up - can confirm pecl uploadprogress is on, and activated from the status reports page.

But how do I see this for uploading files? I've recently enabled the handy drag and drop upload module from here - which supports the progress bar, but whenever I upload something it's just a spinning gif.  I can't find where to alter the progress indicator as mentioned in the answer in the first link above - can anyone point me in the direction?

cheers

Managed to solve this by changing the widget type of the field - back to normal 'File'. Then if you go to the manage field display for this, you should now have an option to set the progress indicator to either 'Throbber' or 'Progress Bar'. If you select progress bar, then flip the widget type back to drag n drop module - it seems to do the trick. Cheers


How can I turn a list of Aliases into a menu structure? I'm in a massive migration from a home grown CMS. So far I've been successful at using Feed Import to slurp in CSV exports of the old MySQL database. The old database contained page URLs. So I just mapped this over to Page Alias!

Now I'm searching for a more automated way to take this

/program/science/thesis
/program/math/core_requirements
/program/science/projects
/program/literature/great_works_collection
/program/literature/great_authors_showcase

into a menu structure like this:

Navigation Menu
+- Program
  +-science
    +-thesis
    +-projects
  +-math
    +-core_requirements
  +-literature
    +-great_works_collection
    +-great_authors_showcase

Yes, I could do this manually, but I have over two thousand imported pages.

Is there an Alias URL to Menu structure script or module that may help me along?

Update:

Based on feedback below, I decided to pull a list of URLs from the CSV file using the following pipe line. That is, I pulled only 5th column (the URLs), sorted the output, filtered urls that had "/programs/", and cut off the trailing quote

awk -F ',"' '{print $5}' programs.csv | sort | grep programs | sed "s/\"//g"

After that was exported to a file, a ran the following to generate the child items of the menu:

cat programs.just.urls.txt | awk -F '/' '{print $3}' | egrep -v "php$" | uniq

I'd give the Menu Export/Import module a go.

  This module helps to export and/or import menus. Using it you can
  easily copy menus from one Drupal site to another.

  It also allows developers to quickly build a new Drupal site by
  creating empty content and menu items referencing it. The module may
  be used in ensemble with Node export that allows to add content to
  your Drupal site. In this case, menu import allows to batch-arrange
  existing content into a given menu structure, using a very simple text
  file.

I guess you could possibly use Excel or something to take your list of aliases and split the paths to columns which would give you the menu title (in the last column of the split).

From there you have the menu link titles and paths, so it's just a case of getting it into the format that the module expects.


Use responsive images inline I can see that using styles on inline images have been left out for some reason. But when I need to make the site behave a little more responsive.

I have been looking after CKeditor plugins that could select a style for the image being include. But I haven't found any.

I have been looking after at comment on the Drupal 7 Picture module that should be what is the base for the implementation of Responsive Images in Drupal 8. But there is nothing about inline images to find - just old Drupal 7 demos on how it should work.

Any idea how to get responsive images or just a basic image style for images include in inline editor on Drupal 8?

The module Entity Embed will be able to do that. There is now a dev version available, but you better wait for the first alpha/beta-release.

Even longer it will take, until this is in core:

Allow image style/responsive image mapping to be selected in Text Editor's image dialog

This is postponed to drupal 8.1

Until then you can use jquery to move the image from an image field to an empty container in the body. To avoid flicker effects, add a style display:none in the twig template of that specific image field and show it after moving it into the body in jquery.


How to have separated enabled modules in multisite based on Domain Access? I have installed 'Domain Access' module to handle some sub-domains on a multisite installation based on Drupal 7.

This module share users, nodes and modules. But I want to have separated modules enabled on each sub-domain. But it seems if I enable a module it will be accessible on all the sub-domains.

Is the any way to bypass it? Sharing users and nodes are good points of this module and I need them but sharing modules ... no.

It's been a year or two since I have used the Domain Access module on a site, but I don't think this is possible.

Domain Access runs all of the affiliate sites out of the same database, so there is a single {system} table, which is where all of the module info it.  Essentially, the module provides some content access rules based on domain (ie, node_access() based controls), along some helpers for other site-specific tasks and integration with other modules.  In the end, though, you still have a single database which means you have a single site.


how view count number vote fivestar on comment? it like this.
examp:

5 star ***** (15)
4 star **** (150)
3 star *** (2)
2 star ** (0)
1 star * (12)

now.

15 is number comment vote 5star for node this
150 is number comment vote 4star for node this
2 is number comment vote 3star for node this
....

This examp other:

You can check this page at Drupal.org: Fivestar 7.x: Creating a User Comment/Rating and Average Rating for a Content type.

If you use the Fivestar voting module, your content will have own rating and reviews, and each contents each comment will have its own rating and review.


How to list all taxonomy terms in a vocabulary followed by associated node titles in Views I am trying to list all of the taxonomy terms from a vocabulary in views and have the node title of all of the nodes that have that term associated with them listed under each term. For example, I have a vocabulary of State names. The various nodes have a term reference field to link the node with a state. I then want to create a view that will show the state name followed by the nodes with that state name, then the next state name etc. I can create a taxonomy view that lists all of the state names, but can't find a way to add the node titles under each state name. I am converting an existing non-Drupal site to Drupal 7.

Here is a link to the current page that I want to make happen in Drupal. It shows the states following by what would be the node titles for each state.

http://www.cbfisk.com/do/DisplayInstrumentList/filter/geographic

Thank you for any help.

Create a view in following way,

1. create a new view to show taxonomy terms of type state
2. Then click relationship under advanced, and choose 'Taxonomy term: Content with term'
3. Then under 'fields' add ' Content: Title' as new field, by keeping relationship 'node'
4. Under 'format' choose HTML list (or table), and set  Taxonomy term: Name  as grouping   field
5. You can choose 'exclude from display' option for field  Taxonomy term: Name

Then you will get the output in desired format as below,


Can any of the cache_* be emptied safely? Sometimes when moving the database it can be too large. Can any of the "cache_" prefixed tables be emptied without causing problems?

With one exception, yes. That exception is cache_form. That is not actually a cache table but contains temporary $form_state information of forms currently displayed on your site. Clearing that table would invalidate these forms and when a user then tries to submit that form, he will get an error message and has to fill out that form again.

Note that drush sql-dump and Backup and Migrate automatically leave out the content of these and other tables when creating a database dump with these instead of mysqldump or phpmyadmin.


Redirect when submit Feedback form I have made a Feedback Form in comments entity, Each node has multi file fields, I'm looking to force the users to submit the form & give their feedback after that redirect them to file download when click submit button, I'm using Views & Custom Formatters and I made the feedback form displays in Colorbox popup to keep them on the same page

feedback URL "node/%/feedback"

is there any function that can help me ? I'm using Drupal 7

You have to add a submit function if you dont have and set the url you want redirect in $form_state['redirect'].

function my_custom_form_submit($form, &$form_state) {
  $form_state['redirect'] = 'node/10';
}

More information here.


How to combine content from two different environments? We have two Drupal environments: dev and prod.  We use dev to stage content before it goes to production.  We also have prod, where content is created and then have to manually re-create those changes back on dev.

Is there a way to combine/merge content changes between the two environments simply/easily?  This is purely content (i.e. nodes) and not code or configuration.

Node Export
The Node Export module might be used for this. Here is an excerpt from its project page:

This module allows users to export nodes and then import it into another Drupal installation, or on the same site.
Using this module you can save yourself a lot of time setting up new websites that have similar nodes to websites you've already made, migrating nodes to new Drupal versions, or between development/staging/production sites.
You will need the same content types for the imports to work (unless using Feeds to import), and ideally relevant compatibility with fields, and modules.

Feeds
Another option that might work is to use the Feeds module. Here is an excerpt from its project page:

Import or aggregate data as nodes, users, taxonomy terms or simple database records.

Bundle copy
Yet another approach is to use the Bundle copy module. Here is an excerpt from its project page:

Has export/import support for:

Node types
Taxonomy
User
Field API fields
Field groups

You can find the export/import links for the supported entities on following paths:

Nodes: admin/structure/types
Taxonomy: admin/structure/taxonomy
Users: admin/config/people/accounts


Customize the user-edit page I want to customize the user-edit page. So in my template.php in my custom theme i direct Drupal to look for my custom template as:

function mytheme_theme() {
return array(
// The form ID
'user_profile_form' => array(
// Forms always take the form argument.
'arguments' => array('form' => NULL),
'render element' => 'form',
'template' => 'templates/user-profile-edit',
),
);
}

This works fine as Drupal is able to pick my custom user-profile-edit.tpl.php. Inside that file i have rendered some elements as :

<?php

print render($form['form_id']);
print render($form['form_build_id']);
print render($form['form_token']);

print render($form['field_birthday_user']);
print render($form['field_real_name_user']);

And so on.I have two questions...How do i get the user picture field, username, password, and email id fields to edit and how do i get to save the profile, i.e., how to get the save button. For the first part i tried doing:

print render($form['account']);

However, this does not displays the user picture.

For the second part, i tried doing this :

<input type=”submit” name=”op” id=”edit-submit” value=”Save”  />

at the end of my custom user-profile-edit.tpl.php. However i get an error regarding syntax.

Would appreciate any suggestions especially regarding the user picture thing.

Thanks

print drupal_render($form['actions']);

that should output the save button


How is the views row plugin set? Can I use a views row plugin from a different module? I'm writing a custom display plugin for views in Drupal 8, and I'm having a hard time figuring out how the view row plugin is decided.

I'm basing my plugin on the views Serializer style in the rest module. The serializer style is calling out to a row style, either DataEntityRow or DataFieldRow:

public function render() {
  $rows = array();
  // If the Data Entity row plugin is used, this will be an array of entities
  // which will pass through Serializer to one of the registered Normalizers,
  // which will transform it to arrays/scalars. If the Data field row plugin
  // is used, $rows will not contain objects and will pass directly to the
  // Encoder.
  foreach ($this->view->result as $row) {
    $rows[] = $this->view->rowPlugin->render($row);
  }

Somewhere along the line, the rowPlugin is being set to one of the aforementioned styles but I can't figure out whether it's set somewhere and I'm missing it, or if it's auto detected in some way. As far as I can tell, the row plugin is never directly instantiated anywhere.

If it is some sort of automatic detection, is there any way for me to hint or force the use in my own code? I could happily use the DataFieldRow plugin in my own class, but I don't know how.

Row is just a plugin. You can write your own.
See the core/modules/views/src/Plugin/views/row directory.


How to sell credits as products, using commerce module? The ideas is to allow users to buy credits through Paypal etc. and only using that credits, they can buy 'real' products. I appreciate your hints to set this up.

Have a look at the Commerce Userpoints* project. It allows to buy things using userpoints and there is also a feature that allows to buy userpoints that is based on a custom product type and rules, so fully customizable.

It most likely doesn't everything that you need, but it might be a start.

There is also Commerce credits and more similar projects, but I haven't tried them out, no idea what exactly they do and how well they work.

*Disclaimer: I am the maintainer of the Userpoints project and I was also involved in that project and still have some code lying around to re-work the UI and improve it.


Expose views as JSON I'd like to expose data/views coming from 6.19 as json.

What I tried so far are the JsonRPC/REST service modules, but none of them worked for me.

Sounds that you need Views Datasource module:

  Views Datasource is a set of plugins for Drupal Views for rendering content in a number of shareable, reusable formats based on XML, JSON and XHTML.


Custom error message + hide generic message I'm working with the Brightcove Drupal module, and want to override generic error messages for users when an upload fails. I've added a custom error - but the generic message is still displaying before the custom message as follows:

Notice: Undefined index: widget in brightcove_field_browser_validate() (line 296 of /path/to/sites/all/modules/my_module/my_module/my_module.module).
This video is currently unavailable. Please note, it may take several minutes for large files to finish processing after being uploaded.

I can post code from the module if needed, but wasn't sure if this could be updated globally to always hide this type of message for users while still keeping custom 'user-friendly' messages.

Thanks!

you can use the theme_status_messages function to do search and suppress certain messages.

The String Overrides module lets you do global text replacements which should work in your case.


Using the CodeMirror Syntax Highlighting plugin with CKeditor and the WYSIWYG module I've installed the latest version of CKeditor and everything works great. However, I wanted to install the CodeMirror Syntax Highlighting Plugin to use it for my editor.

I downloaded the plugin: http://ckeditor.com/addon/codemirror
I extracted the plugin into the plugins directory
I added config.extraPlugins = '[ codemirror ]'; to the config.js file

When I go to the WYSIWYG Profiles section to enable the plugin, it is not there.

Has anyone successfully done this? I've also cleared the cache multiple times.

You can install CodeMirror as a library, and then make a "FULL HTML" profile in WYSIWYG. In practice, you'd get a drop-down entry for it on your edit page (e.g. the ability to switch editors to CodeMirror instead of CKeditor), and a config page within the WYSIWYG module. It's not fully flushed out, but is workable enough to use in production, and TwoD has given really strong input for how we could finish it up properly.

Alternately, you could try to get it working as a CKeditor plugin. You'd get a button toggle in CKeditor, but no configurability within the WYSIWYG module (which defeats the purpose of using WYSIWYG in the first place, IMHO). Haven't tried that one, but my read is that it works.

If you're not too concerned about configurability, you might be able to just drom WYSIWYG completely, and use the original CKeditor module instead. According to one of the folks in those linked threads, CodeMirror works with it out of the box.

There's also a TinyMCE integration module, wysiwyg_codemagic, that supposedly works.


How do I achieve this effect? There are 50+ categories on my site,i want each category to achieve this effect:One row ,4 products.

I do not clone views one by one.
Anyone can help me? THX

Note:I use drupal 7.

You can try Views Fluid Grid module

This module provides the Fluid Grid style plugin for Views. This plugin displays the view as a fluid grid using an HTML list element.

  The plugin settings form provides options to define the width and
  height of the elements in the grid. But it also provides advanced
  layout options implemented in separate CSS classes that allow you to
  define item margins, alignment and a couple of CSS3 properties
  (box-shadow and border-radius).


Drupal 7 module - page layout changes I'm new to Drupal development and this question may have been asked and answered but I haven't found an answer that works for me yet.

I am developing a module that creates 4 paths using a menu_hook. Three of the pages appear inside an iframe defined on a page. I'd like to prevent the header/sidebars/footer (and other regions other than content) from appearing on the iframed page. This must be done independent of the theme - I don't know or care what the theme is.

I'd like the iframed page to only contain the  content  tags. I want to do this programmatically without the help of any additional modules. The iframed page executes a js script (on load) that redirects (the parent) to a results page. It is during the redirect that I can see the loaded iframed page and then the redirection occurs. The transition is ugly.

I have tried using templates in the module directory; however, I don't think I've done them correctly and haven't yet encountered a good example of a template loaded and used from a module directory.

I have tried a hook_page_alter function to unset the regions (but the header and footer still appear on the page).

I've tried a theme_hook function but I'm only interested in suppressing some of the regions the theme may be using and not interested in variables.

Because I don't know what the theme is and I don't know what the selector names or classes might be for the page divs I don't want to try and solve this with a few "display:none;" entries in a css file. Any help or ideas would be appreciated.

Module:

The Empty Page module is a simple empty page solution. It provides an interface that assists in managing "empty" menu callbacks, mostly used for pages that only consist of blocks.
The Panels module allows a site administrator to create customized layouts for multiple uses.
Context allows you to manage contextual conditions and reactions for different portions of your site. For each context, you can choose what blocks to show.

Theming:

Template suggestions are alternate templates based on existing .tpl.php files. You can write in preprocess_page , where put condition and if true, assign page template to page--empty.tpl.php - here you should remove all regions printing except content - so you will get empty page.


Implementing Custom Cache Tags I would like to use the new Cache Tagging in D8 to help keep related content of different types (entities, nodes, blocks, etc) in sync. But from reading the currently available documentation of this feature I do not understand how to add my own cache tag to the items of content when creating/updating said items.

For example when creating a new node of an type Store I would like to add the cache tag location:new_york_123 and the same for a a block. Then if I changed the display name of the New York 123 location to SoHo, I could invalidate the cache tag and have all related content update.

Here is how to use cache tags in the context of custom blocks which I have tried and works but I think it applies to other contexts
Use default drupal tags
In the build array you can specify cache > tags > node_list and this block content would get invalidated (refreshed) when ANY NODE is  changed with nothing else to do on your part
public function build() {
    return array(
        '#markup' => MY_MODULE_awesome_dynamic_node_content(),
        '#cache' => [
            'tags' => ['node_list'], //invalidate when any node updates
            //'tags' => ['node:1','term:2'], //invalidate when node 1 or term 2 updates
        ],
    );
}

Alternatively you can put in one or more node/term/user IDs to invalidate the array on specific nodes or terms as shown in the code comment above.  Note: you can mix and match nodes, terms, users and custom tags as you see fit.
Use your own tags
if you want to have your own way of clearing your build array add your custom unique tag in the build array (any unique string will do)
public function build() {
    return array(
        '#markup' => MY_MODULE_awesome_dynamic_node_content(),
        '#cache' => [
            'tags' => ['MY_CUSTOM_UNIQUE_TAG'],
        ],
    );
}

and in your custom code logic call invalidateTags with your own tag
function MY_MODULE_custom_clear_cache_logic(){
    ...
    \Drupal\Core\Cache\Cache::invalidateTags(array('MY_CUSTOM_UNIQUE_TAG'));

if you want to read more about drupal 8 cache internals


Undefined variable - base_url in include() in Drupal 7 html.tpl.php I am getting this error, but everything else is fine; even that variable is getting printed. Then why does the error appear?

Notice: Undefined variable: base_url in include() (line 26 of htdocs\atins\drupal\sites\all\themes\live\html.tpl.php).
Notice: Undefined variable: base_path in include() (line 26 of htdocs\atins\drupal\sites\all\themes\live\html.tpl.php).

This is my code:
<a href="<?php print $base_url;?>"><img src="<?php print $base_path . $directory; ?>/img/logo.png" height="35" width="211" alt="AtinsLive Logo" title="Home" />

You will need to bring the variable $base_url and $base_path into the global scope. At the top of your function or template file add:

global $base_path, $base_url;

or call base_path()


How to set a custom class to submenus I am working on sidebar menu in a Custom Drupal 8 Theme. I am trying to set a class of sidebar__menu--submenu-1,sidebar__menu--submenu-2, sidebar__menu--submenu-3 and so on depending on the level of the submenus.

So far, I was able to add the class sidebar__menu to the first level & sidebar__menu--submenu to all the submenus. However, I want to add the class sidebar__menu--submenu-(number of the level) so I can style & control the sidebar better on css.

Any help will be really appreciate it!

Here it is my code menu.html.twig:

{{ menus.menu_links(items, attributes, 0) }}

{% macro menu_links(items, attributes, menu_level, menu_name) %}
  {% import _self as menus %}
  {%
    set menu_classes = [
      'sidebar__menu' ~ menu_name|clean_class,
    ]
  %}
  {%
    set submenu_classes = [
      'sidebar__menu' ~ menu_name|clean_class ~ '--submenu',
    ]
  %}
  {% if items %}
    {% if menu_level == 0 %}
      <ul{{ attributes.addClass('container mx-auto', menu_classes) }}>
    {% else %}
      <ul {{ attributes.removeClass(menu_classes).addClass(submenu_classes) }}>
    {% endif %}

    {% for item in items %}
     {%
      set classes = [
        'sidebar__item',
        item.is_expanded ? 'sidebar__item--expanded',
        item.is_collapsed ? 'sidebar__item--collapsed',
        item.in_active_trail ? 'sidebar__item--active-trail',
      ]
      %}
      <li{{ item.attributes.addClass(classes) }}>
        {{ link(item.title, item.url) }}
        {% if item.below %}
          {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
        {% endif %}
      </li>
    {% endfor %}
    </ul>
  {% endif %}
{% endmacro %}

Here's one way to modify your code to add a unique class for each menu level dynamically:

Add a new class appended with the value of menu_level plus one:

  {%
    set submenu_classes = [
      'sidebar__menu' ~ menu_name|clean_class ~ '--submenu',
      'sidebar__menu--submenu-' ~ (menu_level + 1),
    ]
  %}

Remove the previously added class, otherwise I believe it will add the class for each level incrementally.

    {% if menu_level == 0 %}
      <ul{{ attributes.addClass('container mx-auto', menu_classes) }}>
    {% else %}
      <ul{{ attributes.removeClass(menu_classes, 'sidebar__menu--submenu-' ~ (menu_level)).addClass(submenu_classes) }}>
    {% endif %}


Integrate the drupal distribution with already existing site I have already existing Drupal 7 site, now I got a requirement for the jobs portal for the same site, I found there is a nice drupal distribution Recruiter which exactly satisfies my requirements.

I want to know is there any way that I can integrate this distribution with my existing site, so that i can access the functionality of this distribution from my existing site drupal dashboard, please let me know, I searched a lot on this but did not got any relevant info.

I am thinking of one more option if I will create a multisite on my existing drupal site then can I install this distribution on my multisite.

If any option among these two is possible then please let me know, otherwise I have to create a new installation of Drupal and I do not want two dashboards one of my existing site and other of this distribution.

Have you tried the Recruiter Features module?

You can simply download and enable this feature instead of the install profile and see if it does what you need.


How to display a block if a user does NOT have a selected role? I am thinking this has been solved elsewhere, but I haven't found anything.

I am looking for a way to display a block if the current user doesn't have a role. So, whilst the typical permissions allow a block to be displayed to everyone (by not selecting anyone) or to users with specific roles (by selecting a role), I need the inverse, displaying where the user doesn't have a selected role.

DO you have any ideas?

In global variable $user are stored all roles that current user has. So in template.php or template suggestion files you can check if your targeted role is in $user->roles and display block if not.


Adding icons from the right or left to menu H2 or Li Let's say I want to add Icons from the right\left of a Drupal menu H2 or li (such as in the place in the picture)... Actually I would also like to put a picture as a menu item by itself...

What is a good, veteran, and trusted module you could recommend for achieving all of these targets?

Thanks.

What a coincidence. I made good use of this module today because I needed to have bolded text in my menu items:

https://www.drupal.org/project/menu_html

After enabling you'll get a checkbox on each menu item that allows you to add HTML to the menu title (anything inside the anchor essentially). So this is where you would put your <img> tag or the markup necessary for your icons.

Note for security, make sure only trusted users have the ability to use this option, as you can imagine it creates an opportunity to embed malicious code.

EDIT: OP asked how you might add icons using this technique. I would use an icon font. For example with Font Awesome you can put in some markup like <i class="fa fa-refresh"></i> and it will  use CSS to display the icon there. Font Awesome covers most bases. If you can't find something specific try icoMoon or Fontastic.

It's really up to you how you implement this. See the other poster's answer for a pure CSS solution.


Is there a field type that offers structured entry that gets rendered as a table? In the creation of a content type, is there a field type that offers structured entry that gets rendered as a table?

I'm creating an event node, and on the 'full content' display, there are 'sessions' at the event.

Doing a table in the CKeditor isn't enough, and referencing nodes of a different type is too much.

I need something that starts with these columns and one blank row at the bottom, where the end user/content manager can add information like "Date (datepicker)  |  Discussion Topic  |  Room  |  Timeslot(timepicker)  |  Speaker."

Adding information in each column will cause a new blank row for entry.
When the whole node gets submitted, and rendered in 'full-content' display, a table is rendered with that data, as entered on the backend.

Any suggestions on where to look?

Take a look at these modules:

TableField
CCK Table Field


Adding a header to a views glossary I currently have a glossary view set up using attachments in views using Drupal 7. I would like to have a header on top of the list of results displaying an  element of the currently selected letter with a divider (top image). So far I've tried setting up a footer on the attachment but can't seem to figure a way to extract the current letter into the footer (bottom image).

 .

I would like the view to look the same way the top image does. I've hardcoded the letter 'A' into the footer but am looking for a way to make it change with the letter selection.

You need to be able to perform business logic (php) in your Views header (or footer) to perform this task.

The Views header or footer should be able to accept PHP, just change the input filter to PHP. If that input filter is not available, you'll need to enable the PHP Filter module (core, optional) first.

Once you can use PHP in the Views attachment header or footer you can include logic to look at the selected glossary item such as:

$term = check_plain($_GET['glossary_term');
echo "
" . $term . "
";

Then use whatever CSS you need in your theme or module to make this Letter appear however you wish.


Seeking good IM/chat modules My users are asking for "chat", but I suspect they mean one on one IM rather than multi-uer chat rooms.

If there is no negative interaction, I could offer both.

There seem to be a few available, so I will just install them all and try them out one by one, unless someone can make a recommendation.

I need something stable for Drupal 7, easy to use for non-sophisticated users (although they all use IM & FB and the like).

We have Organic Groups so anything that can leverage that somehow might be a bonus.

Update: I am not asking what is "best". I am asking what is stable, well supported, easy to install and administer and easy for unsophisticated users. I ought to have made that clearer before. I just want to cut down my search list.

Review: Drupal Chat has a live demo, so try it out.

There is a small grey box labelled "Chat" permanently at the bottom of the screen, showing the number of on-line users. Clicking reveals a list of users, clicking one begins chat (whether the other user likes it or not).

Options are currently in progress (i.e. none).

User is not informed when partner disconnects and just keeps typing, getting no reply. "go idle/go online" has no effect.

User can chat, but that 's all. Still very much a work in progress as at Nov 2011.

There is a Drupal Chat module for chat. It uses node.js and hence highly scalable

  Supports smileys (detects them automatically in chat messages)
  Chat history is retained in between page loads
  Provides option to use Normal AJAX, long polling and Node.js (only in 7.x) techniques to update chat messages
  Provides optional integration with User Relationships module.


Make Flippy links available in page.html.twig Using the Flippy Module I would like to make the links that it prints in its theme file available in page.html.twig because I want to print them in a different region from where the node content gets printed.

The module states: "If you turn on Flippy for a content type, but hide the pager in the Manage Display page, its links will still be available in the theme layer when it comes time to output node.tpl.php"

That's correct, using Devel Module enter link description here I used dpm(content) on my node.html.twigtemplate.

Doing {{ content.flippy_pager}} allows me to print the links, but it's all within node.html.twig.

How could I possible pass that information on to page.html.twig since my goal is to print it in a different region from where the node's main content gets printed.

I didn't realize the module provides a "Flippy" block.

Remove "Pager" from Structure>Content types>MyContentType>Manage display
Add block in Structure>Block layout. Go to the region you want the links to appear, click Place block, search for Flippy Bock and you are done.

ps: the answer came from stackoverflow, but I reposted it here just in case it's useful for others too.


Changing the content of one node reflecting in other node created using node clone I used node clone to create similar contents. After creating the content using node clone, I have disabled and uninstalled node clone module.

Now, whenever I try to modify something in the cloned content or original node, both are getting reflected with the recent changes. Why is this happening? How do I resolve this?

Note: I have uninstalled the module and cleared performance cache many times now. Weird thing is, these changes are applying only to field collection fields.

The problem with using node clone on node which uses field collection is, it preserves entity reference.

  The group of fields is simply an entity. When you use node clone to
  clone a node the reference to the entity is preserved.

  Quoting from this article.


XML feed data's are importing with the XML tags I have created a XML feeds by the tutorial, but I have found one problem that the XML tags are also appending to data, ie title, description and salary tags are also there
The output is following

<title>Drupal Developer 100</title>

<description>A job creating applications with Drupal.</description>

salary:
<salary ccy="usd">60,000</salary>

The output shows like below, I want to remove <title>

EDIT 1

I get the answer by this tutorial, just uncheck the check-box under "Select the queries you would like to return raw XML or HTML" in XPath XML parser settings

You could use -

  tag/text()

This worked for me. It retrieves all the data that matches the tag.


Get page title form url I have an url like this: http://drupal.dev/en/news-events

It's not my current page url. How can I get the page title by using above url ?

From below code example you can get the page title as your requirement

 $path = \Drupal::service('path.alias_manager')->getPathByAlias('/news-events');
 if(preg_match('/node\/(\d+)/', $path, $matches)) {
  $node = \Drupal\node\Entity\Node::load($matches[1]);
 }
 echo $node->getTitle();

Hope this helps. :)


Theming Site off-line page Is there any way to theme or override the Site off-line page?

The page with below massage:

  The site is currently not available due to technical problems. Please try again later. Thank you for your understanding.

This page uses Garland by default and it has Drupal logo on the page.
I would like to remove this Drupal logo and also change the texts.

Yes, there are 2 templates files that handle this in your theme:

maintenance-page.tpl.php: The theming template used for when your site is in maintenance mode.
maintenance-page--offline.tpl.php: The theming template used for when your site doesn't have database connectivity.

Read Theming the Drupal maintenance page on d.o for more information.


How do you load a select field with pre-selected items when the Chosen module is installed/enabled? How do you load a select field with pre-selected items when the Chosen module is installed/enabled?
I am using the following code.
$my_list = array('item1' = 'item1', 'item2' = 'item2', 'item3' = 'item3');
$form['list_info']['my_list'] = array(
  '#title' => t('Select a list to manage:'),
  '#type' => 'select',
  '#options' => $my_list,
  '#default_value' => $my_list,
);

The select field shows up empty. Clicking it reveals the items and I can select them, but I need the field to show up with the items selected.

Your select field is currently only accepting one selected option. This is why it won't allow an array as a default value. (It expects a string or an integer).
The following select field allows more than a selected option.
$form['list_info']['my_list'] = array(
  '#title' => t('Select a list to manage:'),
  '#type' => 'select',
  '#options' => $my_list,
  '#default_value' => $my_list,
  '#multiple' => TRUE,
);


Error when importing View I am trying to import View from one Drupal 7 Environment (from local to
pantheon one) and got this error:

- Field handler views_entity_commerce_order.operations_dropbutton is not available
- Unable to import view.

Any ideas what is going on here ?

Create a field with machine name 'views_entity_commerce_order' in the pantheon one and then import your view.


how to preserve interface language for a multilingual website? I have a multilingual website with five different languages represented. I have to manage and maintain all the languages, but each time I switch to a particular translation for a piece of content the interface changes too.

I speak English - how do I maintain the interface language in English while managing the translated content?

This too is true for coworkers - the native Japanese speaker needs to be able to maintain the Japanese while he works.

The language preferences for each user is set to their native language - is there a way to have that enforce the interface language we are working in when administering the site?

thanks

Your best bet might be the Administration Language module. It allows you to set the general and user specific administration language. The module doesn't seem to be maintained currently/anymore though and there's only a dev version for the Drupal 7.x branch so you may want to check the bug reports and test it first. I've used it on a few sites without running into any major issues so it should be worth a shot still.


Placing content in different regions using a controller I've defined a route to a custom controller, which returns a render array to define its content. By default, this content gets rendered entirely inside the main content region of the page: what I want is to have different parts of it rendered to different regions.

I've tried specifying the region (e.g. '#region' => 'content_intro') in the relevant sub-arrays for different elements, but they are still output to my main content region.

I've also then tried adding the following to the base definition of the returned render array:

$content = array(
  '#type' => 'page',
);

This does then allow me to successfully specify the region for placing individual elements. However, other standard elements placed in page regions - specifically, a navigation menu block - are then not output.

How would I best go about having my controller add its content to regions, while still retaining elements placed by other systems?

The normal way to do this is to provide the main content in a controller and the additional content in block plugins.

If you don't want to use blocks and the block layout for this task (what you really should do!), and want to solve this in code, you can use a preprocess hook to add content your module provides in a function (procedural or static, not a controller) to a region.


How to hide the "help-block" on an Image field in the Comment Form I have added an image field to the comments.

This allows to my visitors to add images with a comment.

But I have annoying "help-block" for the image field in the form of adding a comment.

How to gracefully to remove this stuff?

Drupal 7

I done it through the node_view_alter hook and my custom theme.

In the theme's template.php file I added the following function

function MyThemeName_node_view_alter(&$build) {
  if ($build['#node']->type !== 'My_Node_Type'){
    return;
  }

  // Your image field can not exist while saving comment.
  if(isset($build['comments']['comment_form']['My_Image_Field'])){
    // We can't use the unset function. Otherwise we can get something like this:
    // Notice: Undefined index: #file_upload_description in theme_file_widget_multiple() (row 863 file .../docs/modules/file/file.field.inc).
    $build['comments']['comment_form']['My_Image_Field']['und']['#file_upload_description'] = NULL;
  }
}

This removes the entire
...
 element.


LDAP integration with drupal I have a LDAP server and my website runs on drupal 6. So i want users from LDAP to access my website using their login details. Which module is preferable for this. i want users to be created on drupal and authentication to happen with LDAP server.

Have you already tried this module?
http://drupal.org/project/ldap_integration

We use this on our (drupal) user control panel to let user authenticate from our LDAP database. Personally I haven't installed it myself, I'm using the drupal 7 version, which works great to!
http://drupal.org/project/ldap


Owl carousel doesn't work I can't understand how to install Owl Carousel module for Drupal 7.

I installed module from here - https://www.drupal.org/project/owlcarousel
And downloaded additional files from here - https://owlcarousel2.github.io/OwlCarousel2/

Put this folder in "sites/all/libraries" and managed fields for my content type. I can see few images on my page, but carousel doesn't work.

Here is the error from chrome console - "Uncaught TypeError: o.owlCarousel is not a function"
"GET https://mysite/owl.carousel.min.js?p44xlt net::ERR_ABORTED"

Bit old, but for module version 1, you have to use OwlCarousel 1
https://github.com/InchoonPark/meteor-owl-carousel-1/


The meaning of form_build_id Can you tell the meaning of form_build_id

I am trying to solve problem "add to cart form breaks after using Exposed filter with Ajax"

As I investigated, only form_build_id value changes when we are trying to search product catalog for certain products with Exposed Filters.

If I take initial form_build_id value for product's add to cart form, search catalog with Exposed Filter, than substitute via Firebug new form_build_id value with initial, and the form works

The form_build_id is used as key to cache a particular build of the form. For multi-step forms, this allows the user to go back to an earlier build, make changes, and re-submit.

See also : drupal_build_form,  drupal_rebuild_form


Display corresponding menu I've several content types configured to add links in several menus other than the main one and navigation, and I'd like Drupal to show in a left sidebar the corresponding menu it belongs and its siblings and children.

How could I achieve that?

Using blocks!

Create your new menu,  and assign it to your left sidebar block.   then, configure that menu's block settings to only appear on certain content types.


Drupal Services OAuth I have been working on this issue for a couple weeks now, and I can't find a solution for the life of me. The fact that I have found no decent documentation (on Drupal's website, or anywhere else) is no help either. And the questions already on here are outdated (Services 2.x).

I'm trying to create a REST service for a Drupal Commerce backed site. For now all the service must do is allow for basic CRUD operations on the Order resource, and be secured with OAuth, OAuth 2.0 isn't necessary. It must also be called with a script on a server, so login re-directs are impossible (everything is done with 2-legged authentication).

The current stack is:

PHP 5.3.15
Drupal 7.15
Commerce Kickstart profile (7.x-2.0-rc1)
Services 7.x-3.2
OAuth 7.x-3.0+18-dev
OAuth Authentication 7.x-3.2
REST Server 7.x-3.2
Commerce Services 7.x-1.x-dev (This is the module I have added my custom Order code to)

I can kind of get the Retrieve/Index functions to work for Orders if I use an OAuth PHP library and just call the token request every time (I'm not even sure what's going on there, except that it authenticates...). If I try to POST to Orders and create an order though, I get 406 with the script, and 401 when I try a direct POST request from the REST Console in Google Chrome, even when OAuth is disabled.

This has made debugging a nightmare since I have no idea what's going on inside my create function. I tried stripping it of its order creation logic and just echo back the request payload. Still get the 406/401 errors.

I assume I get the 401 errors because orders require a user authentication (even if OAuth is turned off for the service).

I don't understand why I'm getting the 406 errors though. I accept application/json, which is what my REST server is set to return.

Orders were not being created even before I commented out the order creation logic. (Which I use elsewhere in the site effectively.)

Appreciation in advance.
-T

Get requests did not need session authentication, POST, PUT, DELETE require session authentication to know the user and check if he has right permissions to complete the request or not.

Oauth authentication have many types of auth you must ensure that you are authentication the user not the an app (for example) so the request is authorized to complete.


Copy the images to the public folder after form submit with PLupload in a custom module I have a custom module to create galleries using PLupload to upload multiple files. These files have a ".tmp" extension in my "/tmp" folder.

Here is an extract of my $form_state['values']:

[0] => Array(
    [tmppath] => temporary://p17g31n52jo4fvj31ds01efd189b4.tmp
    [tmpname] => p17g31n52jo4fvj31ds01efd189b4.tmp
    [name] => photo_1.jpg
    [status] => done
)

How do I save the files in my public folder with the good extension (like .jpg)?
I've tried using file_save_upload() or file_copy() but without success.

Can anyone help me?

I'm on a local server (wamp) as administrator with all permissions. The folders (tmp and site/default) are writable.

I copy here some extracts of my code.

hook_form() :

$form['create']['photos'] = array(
    '#type' => 'plupload',
    '#title' => 'Photos',
    '#upload_validators' => array(
        'file_validate_extensions' => array('jpg jpeg gif png'),
    ),
    '#plupload_settings' => array(
        'runtimes' => 'html5',
        'chunk_size' => '1mb',
    ),
);

hook_form_validate() :

$file = file_save_upload('photos', array(
    'file_validate_is_image' => array(),
    'file_validate_extensions' => array('png gif jpg jpeg'),
));

if ($file) {
    if ($file = file_move($file, 'public://')) {
        $form_state['storage']['file'] = $file;
    } else {
        form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
    }
} else {
    form_set_error('file', t('No file was uploaded.'));
}

It returns "No file was uploaded." I don't understand what I should put as first arguments to the file_save_upload function.

I finally manage to do what I want...

I didn't understand how to use file_copy ans its $destination argument. We can put a file path, not only a folder path. So, I can save my file.jpg correctly.

My code :

$values = $form_state['values']['create'];
$photos_count = count($values['photos']);
for ($i = 0; $i < $photos_count; $i++) {
    $path = $values['photos'][$i]['tmppath'];
    $name = $values['photos'][$i]['name'];
    // set file datas as an object to pass it in file_copy()
    $file = (object)array(
        'uid' => 0,
        'uri' => $path,
        'filemime' => file_get_mimetype($path),
        'status' => 1
    );
    // copy the file in the correct folder
    if ($file = file_copy($file, $filepath . '/' . $name)) {
        drupal_set_message('Success');
    } else {
        drupal_set_message('Error', 'error');
    }
    // set the field datas for saving the node with an array
    $node->field_album_photos[$node->language][$i] = (array)$file;
}

Have a nice day !


Force views to write exposed form block info to {block} table during install profile In a D7 install profile, I am trying to modify the location of a exposed filter block with db_update(), where the view is defined by a module's hook_views_default_views().

At this point it doesn't seem views has collected the views from hook_views_default_views() or the view block does not exist (or db_update cannot address it) in the {block} table until I actually bootstrap Drupal after installation is complete. I have attempted:

Invalidating the views cache via views_invalidate_cache()
Loading the view with views_get_view(NAME)
Triggering drupal_cron_run()

Before issuing the db_update() with no success. I am not versed enough in views to understand at what point views writes the exposed filter blocks to the block table, or how to force it to do so.

I am employing 'cache' => DRUPAL_NO_CACHE, during my db_update() call.

Update : doing a views_get_view() cannot actually load the view. It appears that install profiles do not have access to views provided by hook_default_views.

Thanks.

Doing a views_get_view() cannot actually load the view. From what I can tell, it appears that install profiles do not have access to views provided by hook_default_views.


Better way to associate ticket quantities with event dates? I'm fairly new to events in Drupal 7 but I have at least spent a few days now investigating strategies for my use case. Unfortunately, I haven't found a single relevant piece of info.

I have some recurring events that need to have a remaining tickets number associated with each event date. Some of these events are literally movies in a museum and teachers need to be able to see how many tickets are available for each show time when selecting dates and times for their field trips. Thus, movie show times is a useful (and accurate) model for this issue.

Within a single event node it's simple enough to create multiple date fields and multiple remaining tickets fields for the event. However, I've not been able to figure out how to associate a given remaining tickets number with a specific event date. So far, I only have lists of unrelated dates and numbers.

The alternate "solution" I've come up with is to have an event description node and numerous distinct event date (show time) nodes. The event date (show time) nodes would contain the event date and the tickets remaining for that date. However, I can't think of a way of explicitly connecting the event date nodes to the relevant event description node other than also including the node id in the event date nodes (which, for other reasons, is far from ideal).

Does anyone more experienced with events know whether this explicit connection is even likely to be needed? Even better, can anyone point me in a less cumbersome direction (e.g., associating the tickets required numbers with the right dates, all in one node, instead of creating separate event date nodes)?

Thanks so much for any and all assistance you're able to give!!!
James Baker

If you want to continue down the road you are on now, having an event description node and separate event date nodes, I would recommend you take a look at the References module.

If you want to keep all information within one node for a given movie/event, perhaps take a look at the Field Collection module.  The article Create Multigroups in Drupal 7 using Field Collections may assist you to accomplish this.


How do I fetch the ID from the URL? I have a view which has 2 displays i.e 'page' and 'attachment'.

I am trying to fetch the id from the url and want to display it on 'attachment' display but having difficulty.

On the 'attachment' display, I want to display a text with link to another page alongwith the url id.

If I use 'Contextual filters' then what is the next step to display above text alongwith this id as  tag? or perhaps any other solution.

I found following solution which works for me.....

VIEW > ADVANCED > Contextual filters

Add filter and look for WHEN THE FILTER VALUE IS NOT IN THE URL section.

Select 'Provide default value' > Type: Raw value from url > Path component: ____ (set url id value path number)

e.g if this is url, to get 239066 I will set Path component: 3

(https://drupal.abc.com/questions/239066)

VIEW > Attachment settings > HEADER > Add: Text area > Replacement patterns section will display your url id i.e {{ arguments.url_id }}


Drupal 8 Ajax Callbacks misbehaving when form element in table I have a form containing the following element:

  $form['check'] = array(
    '#type' => 'checkbox',
    '#title' => t('Test'),
    '#ajax' => array(
      'callback' => array($this, 'updateTestCallback'),
      'event' => 'change',
    ),
  );

With the following simple Ajax handler:

  public function updateTestCallback(array $form, FormStateInterface $form_state) {
    $triggering_element = $form_state->getTriggeringElement();
    $ajax_response = new AjaxResponse();
    $ajax_response->addCommand(new AlertCommand($triggering_element['#name']." = ".$triggering_element['#value']));
    return $ajax_response;
  }

This works perfectly when the control is on a plain form, but I want to have a checkbox on every row of a table, and this is where I'm having problems.

I tried using a #table entity, and the checkboxes display correctly, but the Ajax callback event only gets called on every other click (i.e. one click it works, the next nothing happens, the next it works again).

So I should the problem might stem from from the #table entity, so I changed the form to build the table manually using #prefix and #suffix containing the table elements, but this is behaving exactly the same way, so it seems to be the presence of the table elements rather than the way they were generated that's causing the problem.

Here's the current build_form function:

  public function buildForm(array $form, FormStateInterface $form_state, $mid = NULL, $key = NULL) {
    $form = array(
      '#prefix' => '
',
      '#suffix' => '
',
    );

    // Test checkboxes outside table:
    $form['check'] = array(
      '#type' => 'checkbox',
      '#title' => t('Test'),
      '#ajax' => array(
        'callback' => array($this, 'updateTestCallback'),
        'event' => 'change',
      ),
    );
    $form['check2'] = array(
      '#type' => 'checkbox',
      '#title' => t('Test2'),
      '#ajax' => array(
        'callback' => array($this, 'updateTestCallback'),
        'event' => 'change',
      ),
    );

    $form['table'] = array(
      '#prefix' => '
',
      '#suffix' => '
',
    );

    $form['table']['tbody'] = array(
      '#prefix' => '
',
      '#suffix' => '
',
    );
    // Retrieve data and builr one table row per record.
    foreach ($entries = MyStorage::myListLoad() as $entry) {
      $mid = $entry['mid'];
      $is_paid = $entry['is_paid'];
      $row = array(
        '#prefix' => '
',
        '#suffix' => '
',
      );
      $row['first_name'] = array(
        '#markup' => SafeMarkup::checkPlain($entry['first_name']),
        '#prefix' => '',
        '#suffix' => '	',
      );
      $row['last_name'] = array(
        '#markup' => SafeMarkup::checkPlain($entry['last_name']),
        '#prefix' => '',
        '#suffix' => '	',
      );
      $row["is_approved_".$mid] = array(
        //'#attributes' => array('name' => 'is_approved_'.$mid, 'id' => 'edit_is_approved_'.$mid),
        '#type' => 'checkbox',
        '#title' => t('Is Approved'),
        '#title_display' => 'invisible',
        '#ajax' => array(
          'callback' => array($this, 'updateTestCallback'),
          'event' => 'change',
        ),
        '#prefix' => '',
        '#suffix' => '	',
      );
      $form['table']['tbody'][$mid] = $row;
    }
    return $form;
  }

Has anyone come across this problem, and can you suggest a way around it?

James

It's hard to tell without seeing some code of the table. There is probably an error in the structure of the form array. All form elements must have the correct key in the array, which correspondent with the #name. And this keys and names must be unique in the whole form. If you put a form element in a table, use an extra layer to give the element the right key.


How create Menu items by permissions for a view page? My client wants a menu with a link for each content type.

Each item will displayed if the user have permission to create that
content type.
Each item will show a list of content only for that content type.

To accomplish this, I create a view page that have a filter for bundle. In that way I can use same view page for all content types. I tried too, to use same view page like /admin/content but I need to pass the content type to filter for that machine name.

What I trying to do, is create a menu item for each content type, and set permission for each item(link) using the permission that have each content type.

E.g.: My menu have a Item Article. You should see this item only If you have right to create an Article. When you click here you will see all the content Articles(like /admin/content).

It suppose that a user or role, that have permission to create a content type.. should see the item.

How can I create menu items with permission to a view?

There is my issue, because it use the permission in the view page, and not in the route.

.links.menu.yml

content_types.admin_1:
 title: 'Articles'
 parent: content_types.admin_menu
 route_name: content_types.admin_1
 route_parameters:
  type: article
 description: 'Content articles'

content_types.admin_2:
 title: 'News'
 parent: content_types.admin_menu
 route_name: content_types.admin_2
 route_parameters:
  type: nouvelle
 description: 'Content news'

.routing.yml

content_types.admin_1:
  path: '/admin/view-test'
  defaults:
    _controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
    _title: 'Articles'
  requirements:
    _permission: 'create article content'

content_types.admin_2:
  path: '/admin/view-test'
  defaults:
    _controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
    _title: 'News'
  requirements:
    _permission: 'create nouvelle content'

As you see I added _permission: 'create article content' but it didn't do anything.

admin/structure/views/view/view_test?destination=/en/admin/structure/views

The role for the user that I'm using doesn't have permission to create article or news.

UPDATED:

I created a .permissions.yml and used _permission: 'access menu item 1' but it display the item even if this permission is not ticket for that role.

.permissions.yml

'access menu item 1':
  title: Access Menu MTL 1
  description: Allow users to access menu MTL

Any suggestion?

UPDATED: January, 2019

The issue is try to use same view page(/admin/content) for each Content type with different permissions. You dont set permissions to each link, instead you set permission to the view (or item) that you are trying to access.

What I did:

I tried using dynamic menus. But it isn't functional for my purpose. Because, each link menu could have different access by roles.

Then I realized that I needed to create a view for each type of content to be able to manage an individual permission.

Therefore I need to create a view each time that I create a CT, so the is no sense to do it dynamically.

How I did:

I create a view for each CT with a filter content by type. And also I set permission for each view for same CT. And a custom route.

Create one item menu for each CT and set as route same as is in the view.

.links.menu.yml

    vdm.tc_sujet:
     title: 'Sujets'
     parent: system.admin_content
     route_name: vdm.tc_sujets
     description: "Content type subject."
     weight: -1

.routing.yml

    vdm.tc_sujets:
     path: '/admin/content/sujet'
     defaults:
       _controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
       _title: 'Sujets'

As result if user have access to that view the item menu will be displayed.

Note: I think that dynamic menus it fix great for add link item to nodes.


Drupal View 3 / CiviCRM integration - block update depends on user authorization All,

In my CiviCRM installation, I support both Individual Contacts and Organization Contacts. For the Drupal site, there is a block based on a view that exposes some information about Organization Contacts. This view is configured with a Global: Random sort criteria in order to expose three different Organization on each page visit.

When I am logged into the site (as an Authenticated User or Administrator), the block works properly. When I am not logged into the site, the block does not update. Just to be clear: When logged in, reloading the same page results in three different Organization Contacts being displayed. When not logged in, the same three Organization Contacts are displayed each time.

The issue seems to be tied to the cache. When I cleared the Drupal caches, the Organization Contacts for the non-logged in user changed (but then remained the same as described above).

Would you please suggest a fix for this problem. Thank you!

I'm not sure if there's a way around this. Drupal will cache the output of Views to anonymous users, as it does for most pages. Drupal rarely caches content for authenticated users. On top of that, your host may be using a reverse-cache such as Varnish, since it greatly improves performance of Drupal sites for anonymous users.

A workaround could be to reduce the cache time of content. First try by changing the cache settings on the specific View, and if not, try the global setting in /admin/config/development/performance.

However, assuming that the list of contacts you are displaying is a sort of "randomly featured members" type of block, if your cache expires every 15 or 30 minutes, it's still usually pretty sufficient for that type of requirement, unless you have a really high traffic site and you must rotate faster.

If you do have a very high traffic site, I would probably load the block dynamically with Ajax to avoid killing the cache (and cache that block in a more efficient cache such as memcached, which a short expiration time of perhaps 5 minutes).


How to do the live streaming of music channels on my site? I am about to work on internet radio site.How am gonna do the functionality live streaming of channels.Any help will be appreciated .

You can do this by using Live Streaming module.

How to use?


How do I limit permissions to manage an event? I'm using the RNG Event module in D8 and have an issue where any registered user can click on an event and has access to the view and event tabs. And then through the event tab they can access the settings, access, conflicts, etc.

They can also click to view other user's registrations and delete them.

How do I limit normal logged in users to only see the event, and to register or delete a registration for only themselves? If they can see the other registrants that's fine, but they shouldn't be able to delete.

I have checked all normal permissions settings and see nothing that could grant their current level of access. The only other thing I see under Content Type > Event type > Access Defaults are the three stock rules that also seem to be correct.

This may or may not be connected to the issue I'm having here - Why does the "Registration List" tab not appear for my events for users with adequate privileges?

Per the other thread listed above, Daniel answered:

  Are you saying you have never seen the 'Registration list' tab? If
  this is the case you need to create that view by enabling rng_views
  module. Then go to the event type edit form. An option to create the
  view will appear.

This worked perfectly, thanks again Daniel!!


How to add capcha for node/edit form I need to add captcha for node edit form, not for the front-end form. please can any one help me?

I believe you are  using Captcha module..

Go to admin/config/people/captcha
Enable "Add CAPTCHA administration links to forms" and "Allow CAPTCHAs and CAPTCHA administration links on administrative pages"

Go to node edit page you see setting like below

Enable captcha for form


Disable or remove permissions for Scald page display It appears to me that Scald does not have a permission allowing you to set who can view the "page view" of the atom /atom/ATOMID.

Is there some way to restrict access to this page or revoke permissions from roles?

This is a partial answer, simply blocks non-logged in visitors:

function MYMODULE_init() {
  // Prevent public users from seeing the atom pages
  global $user;
  if(arg(0) == 'atom' && !$user->uid) {
    drupal_not_found();
    exit;
  }
}

I would really like it if there was a permission on the scald module, logged an issue on d.o for that https://www.drupal.org/node/2512692.

Edit: there is a patch on that d.o issue which adds a permission to 'access atom page view', which is a better solution to the use of  hook_init() above.


Content display based on user preferences I'm new to Drupal, so I don't know if what I want to do is even possible.
I want to create six checkboxes that represent different languages - let's call them A,B,C,D,E,F so that every user can check as many as he/she wants during registration and change it later (I already did that by adding field in account settings).
Moreover, on one page I'd like to have six blocks of text (one for each language) but only show the checked ones (so each user would see different content).
Finally, I want to enable users to create their own content which would be published after administrator's review - difficult part is that every administrator should have language/-es that he/she specializes in and be able to accept/edit content only in that language/-es.

If I am not being specific enough please let me know and I will try to elaborate.

Thanks for you help!
Dominik

You can accomplish the first by enabling PHP in modules, and making a check in the block configuration / Pages - using php you can check each block for the appropriate $user field and whether or not its set for that particular language.  You could also create a module to build each block programmatically, and then show/hide depending on the field value.

The second can be done with something like this:

Content Type
  * create a hidden field called language

using Rules set an event (After Saving New Content - ), event - set data value - node->language equal to user->language. This will assign a language to each node created
create a view with the relevant fields/information you want presented, and filter on current user:language - in this way each user who sees this view will only see the entries that match their own language settings