# Question
Title: What may cause my custom VBO action to no longer update my Menu Badges counter?
I created a on-site notification system with the help of this post. It was working perfectly, but now suddenly it stopped working. When I visit the page, the menu badge does not disappear.

Recently, I updated the core. Not sure if this is the problem. When I visit the page www.mysite.com/notification, the log shows following errors.

Following is my views, rule and rule component

**Views Export**

```
$view = new view();
$view->name = 'notifications';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'message';
$view->human_name = 'Notifications';
$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'] = 'Notifications';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$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['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Message: User uid */
$handler->display->display_options['relationships']['user']['id'] = 'user';
$handler->display->display_options['relationships']['user']['table'] = 'message';
$handler->display->display_options['relationships']['user']['field'] = 'user';
/* Relationship: Flags: message_viewed */
$handler->display->display_options['relationships']['flag_content_rel']['id'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['table'] = 'message';
$handler->display->display_options['relationships']['flag_content_rel']['field'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['required'] = 0;
$handler->display->display_options['relationships']['flag_content_rel']['flag'] = 'message_viewed';
/* Field: Message: Message ID */
$handler->display->display_options['fields']['mid']['id'] = 'mid';
$handler->display->display_options['fields']['mid']['table'] = 'message';
$handler->display->display_options['fields']['mid']['field'] = 'mid';
/* Field: Message: Render message (Get text) */
$handler->display->display_options['fields']['message_render']['id'] = 'message_render';
$handler->display->display_options['fields']['message_render']['table'] = 'message';
$handler->display->display_options['fields']['message_render']['field'] = 'message_render';
$handler->display->display_options['fields']['message_render']['label'] = '';
$handler->display->display_options['fields']['message_render']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['message_render']['partials'] = 0;
$handler->display->display_options['fields']['message_render']['partials_delta'] = '0';
/* Field: Message: Timestamp */
$handler->display->display_options['fields']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['table'] = 'message';
$handler->display->display_options['fields']['timestamp']['field'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['label'] = '';
$handler->display->display_options['fields']['timestamp']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['timestamp']['date_format'] = 'html5_tools_iso8601';
$handler->display->display_options['fields']['timestamp']['second_date_format'] = 'html5_tools_iso8601';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'user';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['exclude'] = TRUE;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
/* Field: Bulk operations: Message */
$handler->display->display_options['fields']['views_bulk_operations']['id'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['table'] = 'views_entity_message';
$handler->display->display_options['fields']['views_bulk_operations']['field'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['label'] = 'Mark as read';
$handler->display->display_options['fields']['views_bulk_operations']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['display_type'] = '1';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['enable_select_all_pages'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['row_clickable'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
  'rules_component::rules_flag_a_message' => array(
    'selected' => 1,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'skip_permission_check' => 0,
    'override_label' => 1,
    'label' => 'Mark selected message(s) as read',
  ),
);
/* Sort criterion: Message: Timestamp */
$handler->display->display_options['sorts']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['sorts']['timestamp']['table'] = 'message';
$handler->display->display_options['sorts']['timestamp']['field'] = 'timestamp';
$handler->display->display_options['sorts']['timestamp']['order'] = 'DESC';
/* Contextual filter: Message: User uid */
$handler->display->display_options['arguments']['user']['id'] = 'user';
$handler->display->display_options['arguments']['user']['table'] = 'message';
$handler->display->display_options['arguments']['user']['field'] = 'user';
$handler->display->display_options['arguments']['user']['default_action'] = 'default';
$handler->display->display_options['arguments']['user']['default_argument_type'] = 'current_user';
$handler->display->display_options['arguments']['user']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['user']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['user']['summary_options']['items_per_page'] = '25';

/* Display: All */
$handler = $view->new_display('page', 'All', 'page');
$handler->display->display_options['defaults']['relationships'] = FALSE;
/* Relationship: Message: User uid */
$handler->display->display_options['relationships']['user']['id'] = 'user';
$handler->display->display_options['relationships']['user']['table'] = 'message';
$handler->display->display_options['relationships']['user']['field'] = 'user';
/* Relationship: Flags: message_viewed */
$handler->display->display_options['relationships']['flag_content_rel']['id'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['table'] = 'message';
$handler->display->display_options['relationships']['flag_content_rel']['field'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['required'] = 0;
$handler->display->display_options['relationships']['flag_content_rel']['flag'] = 'message_viewed';
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Message: Message ID */
$handler->display->display_options['fields']['mid']['id'] = 'mid';
$handler->display->display_options['fields']['mid']['table'] = 'message';
$handler->display->display_options['fields']['mid']['field'] = 'mid';
$handler->display->display_options['fields']['mid']['label'] = '';
$handler->display->display_options['fields']['mid']['exclude'] = TRUE;
$handler->display->display_options['fields']['mid']['element_label_colon'] = FALSE;
/* Field: Message: Render message (Get text) */
$handler->display->display_options['fields']['message_render']['id'] = 'message_render';
$handler->display->display_options['fields']['message_render']['table'] = 'message';
$handler->display->display_options['fields']['message_render']['field'] = 'message_render';
$handler->display->display_options['fields']['message_render']['label'] = '';
$handler->display->display_options['fields']['message_render']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['message_render']['partials'] = 0;
$handler->display->display_options['fields']['message_render']['partials_delta'] = '0';
/* Field: Message: Timestamp */
$handler->display->display_options['fields']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['table'] = 'message';
$handler->display->display_options['fields']['timestamp']['field'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['label'] = '';
$handler->display->display_options['fields']['timestamp']['exclude'] = TRUE;
$handler->display->display_options['fields']['timestamp']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['timestamp']['date_format'] = 'html5_tools_iso8601';
$handler->display->display_options['fields']['timestamp']['second_date_format'] = 'html5_tools_iso8601';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'user';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['exclude'] = TRUE;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
/* Field: Flags: Flagged time */
$handler->display->display_options['fields']['timestamp_1']['id'] = 'timestamp_1';
$handler->display->display_options['fields']['timestamp_1']['table'] = 'flag_content';
$handler->display->display_options['fields']['timestamp_1']['field'] = 'timestamp';
$handler->display->display_options['fields']['timestamp_1']['relationship'] = 'flag_content_rel';
$handler->display->display_options['fields']['timestamp_1']['label'] = '';
$handler->display->display_options['fields']['timestamp_1']['exclude'] = TRUE;
$handler->display->display_options['fields']['timestamp_1']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['timestamp_1']['date_format'] = 'html5_tools_iso8601';
$handler->display->display_options['fields']['timestamp_1']['second_date_format'] = 'html5_tools_iso8601';
/* Field: Bulk operations: Message */
$handler->display->display_options['fields']['views_bulk_operations']['id'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['table'] = 'views_entity_message';
$handler->display->display_options['fields']['views_bulk_operations']['field'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['label'] = '';
$handler->display->display_options['fields']['views_bulk_operations']['exclude'] = TRUE;
$handler->display->display_options['fields']['views_bulk_operations']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['display_type'] = '1';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['enable_select_all_pages'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['row_clickable'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
  'rules_component::rules_flag_a_message' => array(
    'selected' => 1,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'skip_permission_check' => 0,
    'override_label' => 0,
    'label' => '',
  ),
);
$handler->display->display_options['path'] = 'notification';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Notifications';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['name'] = 'main-menu';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['menu']['context_only_inline'] = 0;

/* Display: Read */
$handler = $view->new_display('page', 'Read', 'page_1');
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Message: Message ID */
$handler->display->display_options['fields']['mid']['id'] = 'mid';
$handler->display->display_options['fields']['mid']['table'] = 'message';
$handler->display->display_options['fields']['mid']['field'] = 'mid';
/* Field: Message: Render message (Get text) */
$handler->display->display_options['fields']['message_render']['id'] = 'message_render';
$handler->display->display_options['fields']['message_render']['table'] = 'message';
$handler->display->display_options['fields']['message_render']['field'] = 'message_render';
$handler->display->display_options['fields']['message_render']['label'] = '';
$handler->display->display_options['fields']['message_render']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['message_render']['partials'] = 0;
$handler->display->display_options['fields']['message_render']['partials_delta'] = '0';
/* Field: Message: Timestamp */
$handler->display->display_options['fields']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['table'] = 'message';
$handler->display->display_options['fields']['timestamp']['field'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['label'] = '';
$handler->display->display_options['fields']['timestamp']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['timestamp']['date_format'] = 'html5_tools_iso8601';
$handler->display->display_options['fields']['timestamp']['second_date_format'] = 'html5_tools_iso8601';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'user';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['exclude'] = TRUE;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
/* Field: Flags: Flagged time */
$handler->display->display_options['fields']['timestamp_1']['id'] = 'timestamp_1';
$handler->display->display_options['fields']['timestamp_1']['table'] = 'flag_content';
$handler->display->display_options['fields']['timestamp_1']['field'] = 'timestamp';
$handler->display->display_options['fields']['timestamp_1']['relationship'] = 'flag_content_rel';
$handler->display->display_options['fields']['timestamp_1']['label'] = '';
$handler->display->display_options['fields']['timestamp_1']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['timestamp_1']['date_format'] = 'html5_tools_iso8601';
$handler->display->display_options['fields']['timestamp_1']['second_date_format'] = 'html5_tools_iso8601';
/* Field: Bulk operations: Message */
$handler->display->display_options['fields']['views_bulk_operations']['id'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['table'] = 'views_entity_message';
$handler->display->display_options['fields']['views_bulk_operations']['field'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['label'] = 'Mark as unread';
$handler->display->display_options['fields']['views_bulk_operations']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['display_type'] = '1';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['enable_select_all_pages'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['row_clickable'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* Filter criterion: Flags: Flagged */
$handler->display->display_options['filters']['flagged']['id'] = 'flagged';
$handler->display->display_options['filters']['flagged']['table'] = 'flag_content';
$handler->display->display_options['filters']['flagged']['field'] = 'flagged';
$handler->display->display_options['filters']['flagged']['relationship'] = 'flag_content_rel';
$handler->display->display_options['filters']['flagged']['value'] = '1';
$handler->display->display_options['path'] = 'notification/read';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Read';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['name'] = 'main-menu';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['menu']['context_only_inline'] = 0;
$handler->display->display_options['tab_options']['weight'] = '0';

/* Display: Unread */
$handler = $view->new_display('page', 'Unread', 'page_2');
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* Filter criterion: Flags: Flagged */
$handler->display->display_options['filters']['flagged']['id'] = 'flagged';
$handler->display->display_options['filters']['flagged']['table'] = 'flag_content';
$handler->display->display_options['filters']['flagged']['field'] = 'flagged';
$handler->display->display_options['filters']['flagged']['relationship'] = 'flag_content_rel';
$handler->display->display_options['filters']['flagged']['value'] = '0';
$handler->display->display_options['path'] = 'notification/unread';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Unread';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['menu']['context_only_inline'] = 0;

/* Display: Unread badge */
$handler = $view->new_display('menu_badge', 'Unread badge', 'menu_badge_1');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['group_by'] = TRUE;
$handler->display->display_options['access']['type'] = 'none';
$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'] = 'some';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Flags: message_viewed */
$handler->display->display_options['relationships']['flag_content_rel']['id'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['table'] = 'message';
$handler->display->display_options['relationships']['flag_content_rel']['field'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['required'] = 0;
$handler->display->display_options['relationships']['flag_content_rel']['flag'] = 'message_viewed';
/* Relationship: Message: User uid */
$handler->display->display_options['relationships']['user']['id'] = 'user';
$handler->display->display_options['relationships']['user']['table'] = 'message';
$handler->display->display_options['relationships']['user']['field'] = 'user';
/* Field: Message: Message ID */
$handler->display->display_options['fields']['mid']['id'] = 'mid';
$handler->display->display_options['fields']['mid']['table'] = 'message';
$handler->display->display_options['fields']['mid']['field'] = 'mid';
$handler->display->display_options['fields']['mid']['group_type'] = 'count';
$handler->display->display_options['fields']['mid']['label'] = '';
$handler->display->display_options['fields']['mid']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['mid']['hide_empty'] = TRUE;
/* Contextual filter: Message: User uid */
$handler->display->display_options['arguments']['user']['id'] = 'user';
$handler->display->display_options['arguments']['user']['table'] = 'message';
$handler->display->display_options['arguments']['user']['field'] = 'user';
$handler->display->display_options['arguments']['user']['default_action'] = 'default';
$handler->display->display_options['arguments']['user']['default_argument_type'] = 'current_user';
$handler->display->display_options['arguments']['user']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['user']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['user']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Flags: Flagged */
$handler->display->display_options['filters']['flagged']['id'] = 'flagged';
$handler->display->display_options['filters']['flagged']['table'] = 'flag_content';
$handler->display->display_options['filters']['flagged']['field'] = 'flagged';
$handler->display->display_options['filters']['flagged']['relationship'] = 'flag_content_rel';
$handler->display->display_options['filters']['flagged']['value'] = '0';

```

**Rule Export**

```
{ "rules_mark_all_unread_messages_read" : {
    "LABEL" : "Mark all unread messages read",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "views_bulk_operations" ],
    "ON" : { "init" : [] },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "2" : "2" } }
        }
      },
      { "text_matches" : {
          "text" : [ "site:current-page:url" ],
          "match" : "notification",
          "operation" : "regex"
        }
      }
    ],
    "DO" : [
      { "views_bulk_operations_action_load_list" : {
          "USING" : { "view" : "notifications|page" },
          "PROVIDE" : { "entity_list" : { "unread_msgs_list" : "A list of unreadmessages" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "unread-msgs-list" ] },
          "ITEM" : { "current_msg" : "Current message" },
          "DO" : [
            { "component_rules_flag_a_message" : { "message_to_flag" : [ "current-msg" ] } }
          ]
        }
      }
    ]
  }
}

```

**Rule Component**

```
{ "rules_flag_a_message" : {
    "LABEL" : "Flag a message",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "flag" ],
    "USES VARIABLES" : { "message_to_flag" : { "label" : "Message to be flagged", "type" : "message" } },
    "DO" : [
      { "flag_flagmessage" : {
          "flag" : "message_viewed",
          "message" : [ "message-to-flag" ],
          "flagging_user" : [ "site:current-user" ],
          "permission_check" : "1"
        }
      }
    ]
  }
}

```

# Answer
"***... it suddenly it stopped working***" are about the toughest support calls to be resolved. I bet something did change somehow/somewhere (intentionally or not doesn't matter), so give it a try to narrow down the actual issue, as detailed below ...

### Narrowing down the actual problem

From the error log you posted in your question, and based on what is shown in the exported view and rule, it is clear (at least to me) that the cause of your issue is related to the very first rules action, which is the only place where you have that `unread_msgs_list` (as shown in the error message also).

Furthermore, that `/notification` path is what I can see in your exported view, and which actually corresponds to the custom VBO action you implemented with the rule in your question also (which in turn invokes the subsequent Rules Component).

### Recommended debugging

Something that might help you find the answer to your question, is to have a look at Rules **debugging** ... Within the Rules **settings**, experiment a bit with the debugging facilities that come with the rules module. At least have a look at the "***Rules Evaluation Log***" (to check that the Rules logic being executed, actually matches what you expect that logic to be).

Depending on what the result of that type of debugging is, you may also want to (temporary) enable the Devel module, so that you can (temporary) add a Rules Action like "Display a value" (though at this point I don't see any value worth displaying for debugging purposes, for that you first need to find anything suspicious in the Rules debugging log).

For way more details about these 2 variations, refer to **Rules debugging**, as explained in the answer to "How can I display the value of a variable inside a condition?".

PS 1: It might help if you add an update to your question, to include the complete message that starts with "`Unable to get unread_msgs_list, it is not ...`"

PS 2: You did a good job to implement what got suggested in the related post.
> 1 votes

# Answer
Well fortunately I had a backup. Views 3.15 is seem to cause problems. The backup had 3.14. Now it is working. The above view might not work. Here is the export of my view in case anyone wants to create a notification system.

View Export

```
$view = new view();
$view->name = 'notifications';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'message';
$view->human_name = 'Notifications';
$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'] = 'Notifications';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$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'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Flags: message_viewed */
$handler->display->display_options['relationships']['flag_content_rel']['id'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['table'] = 'message';
$handler->display->display_options['relationships']['flag_content_rel']['field'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['required'] = 0;
$handler->display->display_options['relationships']['flag_content_rel']['flag'] = 'message_viewed';
/* Relationship: Message: User uid */
$handler->display->display_options['relationships']['user']['id'] = 'user';
$handler->display->display_options['relationships']['user']['table'] = 'message';
$handler->display->display_options['relationships']['user']['field'] = 'user';
/* Field: Message: Message ID */
$handler->display->display_options['fields']['mid']['id'] = 'mid';
$handler->display->display_options['fields']['mid']['table'] = 'message';
$handler->display->display_options['fields']['mid']['field'] = 'mid';
/* Field: Bulk operations: Message */
$handler->display->display_options['fields']['views_bulk_operations']['id'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['table'] = 'message';
$handler->display->display_options['fields']['views_bulk_operations']['field'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['label'] = '';
$handler->display->display_options['fields']['views_bulk_operations']['exclude'] = TRUE;
$handler->display->display_options['fields']['views_bulk_operations']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['display_type'] = '1';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['enable_select_all_pages'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['row_clickable'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
  'rules_component::rules_flag_a_message' => array(
    'selected' => 1,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
);
/* Field: Message: Render message (Get text) */
$handler->display->display_options['fields']['message_render']['id'] = 'message_render';
$handler->display->display_options['fields']['message_render']['table'] = 'message';
$handler->display->display_options['fields']['message_render']['field'] = 'message_render';
$handler->display->display_options['fields']['message_render']['label'] = '';
$handler->display->display_options['fields']['message_render']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['message_render']['partials'] = 0;
$handler->display->display_options['fields']['message_render']['partials_delta'] = '0';
/* Field: Message: Timestamp */
$handler->display->display_options['fields']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['table'] = 'message';
$handler->display->display_options['fields']['timestamp']['field'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['label'] = '';
$handler->display->display_options['fields']['timestamp']['exclude'] = TRUE;
$handler->display->display_options['fields']['timestamp']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['timestamp']['date_format'] = 'short';
$handler->display->display_options['fields']['timestamp']['second_date_format'] = 'long';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'user';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['exclude'] = TRUE;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
/* Sort criterion: Message: Timestamp */
$handler->display->display_options['sorts']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['sorts']['timestamp']['table'] = 'message';
$handler->display->display_options['sorts']['timestamp']['field'] = 'timestamp';
$handler->display->display_options['sorts']['timestamp']['order'] = 'DESC';
/* Contextual filter: Message: User uid */
$handler->display->display_options['arguments']['user']['id'] = 'user';
$handler->display->display_options['arguments']['user']['table'] = 'message';
$handler->display->display_options['arguments']['user']['field'] = 'user';
$handler->display->display_options['arguments']['user']['default_action'] = 'default';
$handler->display->display_options['arguments']['user']['default_argument_type'] = 'current_user';
$handler->display->display_options['arguments']['user']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['user']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['user']['summary_options']['items_per_page'] = '25';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'notification';
$handler->display->display_options['menu']['type'] = 'tab';
$handler->display->display_options['menu']['title'] = 'Notifications';
$handler->display->display_options['menu']['weight'] = '0';
$handler->display->display_options['menu']['name'] = 'main-menu';
$handler->display->display_options['menu']['context'] = 0;
$handler->display->display_options['menu']['context_only_inline'] = 0;

/* Display: unread */
$handler = $view->new_display('page', 'unread', 'page_1');
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Message: Message ID */
$handler->display->display_options['fields']['mid']['id'] = 'mid';
$handler->display->display_options['fields']['mid']['table'] = 'message';
$handler->display->display_options['fields']['mid']['field'] = 'mid';
/* Field: Bulk operations: Message */
$handler->display->display_options['fields']['views_bulk_operations']['id'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['table'] = 'message';
$handler->display->display_options['fields']['views_bulk_operations']['field'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['label'] = '';
$handler->display->display_options['fields']['views_bulk_operations']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['display_type'] = '1';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['enable_select_all_pages'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['row_clickable'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
  'rules_component::rules_flag_a_message' => array(
    'selected' => 1,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
);
/* Field: Message: Render message (Get text) */
$handler->display->display_options['fields']['message_render']['id'] = 'message_render';
$handler->display->display_options['fields']['message_render']['table'] = 'message';
$handler->display->display_options['fields']['message_render']['field'] = 'message_render';
$handler->display->display_options['fields']['message_render']['label'] = '';
$handler->display->display_options['fields']['message_render']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['message_render']['partials'] = 0;
$handler->display->display_options['fields']['message_render']['partials_delta'] = '0';
/* Field: Message: Timestamp */
$handler->display->display_options['fields']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['table'] = 'message';
$handler->display->display_options['fields']['timestamp']['field'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['label'] = '';
$handler->display->display_options['fields']['timestamp']['exclude'] = TRUE;
$handler->display->display_options['fields']['timestamp']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['timestamp']['date_format'] = 'short';
$handler->display->display_options['fields']['timestamp']['second_date_format'] = 'long';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'user';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['exclude'] = TRUE;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
/* Field: Flags: Flagged time */
$handler->display->display_options['fields']['timestamp_1']['id'] = 'timestamp_1';
$handler->display->display_options['fields']['timestamp_1']['table'] = 'flag_content';
$handler->display->display_options['fields']['timestamp_1']['field'] = 'timestamp';
$handler->display->display_options['fields']['timestamp_1']['relationship'] = 'flag_content_rel';
$handler->display->display_options['fields']['timestamp_1']['label'] = '';
$handler->display->display_options['fields']['timestamp_1']['exclude'] = TRUE;
$handler->display->display_options['fields']['timestamp_1']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['timestamp_1']['date_format'] = 'long';
$handler->display->display_options['fields']['timestamp_1']['second_date_format'] = 'long';
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* Filter criterion: Flags: Flagged */
$handler->display->display_options['filters']['flagged']['id'] = 'flagged';
$handler->display->display_options['filters']['flagged']['table'] = 'flag_content';
$handler->display->display_options['filters']['flagged']['field'] = 'flagged';
$handler->display->display_options['filters']['flagged']['relationship'] = 'flag_content_rel';
$handler->display->display_options['filters']['flagged']['value'] = '0';
$handler->display->display_options['path'] = 'notification/unread';

/* Display: read */
$handler = $view->new_display('page', 'read', 'page_2');
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Message: Message ID */
$handler->display->display_options['fields']['mid']['id'] = 'mid';
$handler->display->display_options['fields']['mid']['table'] = 'message';
$handler->display->display_options['fields']['mid']['field'] = 'mid';
/* Field: Bulk operations: Message */
$handler->display->display_options['fields']['views_bulk_operations']['id'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['table'] = 'message';
$handler->display->display_options['fields']['views_bulk_operations']['field'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['label'] = '';
$handler->display->display_options['fields']['views_bulk_operations']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['display_type'] = '1';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['enable_select_all_pages'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['row_clickable'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
  'rules_component::rules_flag_a_message' => array(
    'selected' => 1,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
);
/* Field: Message: Render message (Get text) */
$handler->display->display_options['fields']['message_render']['id'] = 'message_render';
$handler->display->display_options['fields']['message_render']['table'] = 'message';
$handler->display->display_options['fields']['message_render']['field'] = 'message_render';
$handler->display->display_options['fields']['message_render']['label'] = '';
$handler->display->display_options['fields']['message_render']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['message_render']['partials'] = 0;
$handler->display->display_options['fields']['message_render']['partials_delta'] = '0';
/* Field: Message: Timestamp */
$handler->display->display_options['fields']['timestamp']['id'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['table'] = 'message';
$handler->display->display_options['fields']['timestamp']['field'] = 'timestamp';
$handler->display->display_options['fields']['timestamp']['label'] = '';
$handler->display->display_options['fields']['timestamp']['exclude'] = TRUE;
$handler->display->display_options['fields']['timestamp']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['timestamp']['date_format'] = 'short';
$handler->display->display_options['fields']['timestamp']['second_date_format'] = 'long';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'user';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['exclude'] = TRUE;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* Filter criterion: Flags: Flagged */
$handler->display->display_options['filters']['flagged']['id'] = 'flagged';
$handler->display->display_options['filters']['flagged']['table'] = 'flag_content';
$handler->display->display_options['filters']['flagged']['field'] = 'flagged';
$handler->display->display_options['filters']['flagged']['relationship'] = 'flag_content_rel';
$handler->display->display_options['filters']['flagged']['value'] = '1';
$handler->display->display_options['path'] = 'notification/read';

/* Display: Menu badge */
$handler = $view->new_display('menu_badge', 'Menu badge', 'menu_badge_1');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['group_by'] = TRUE;
$handler->display->display_options['access']['type'] = 'none';
$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'] = 'some';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Message: User uid */
$handler->display->display_options['relationships']['user']['id'] = 'user';
$handler->display->display_options['relationships']['user']['table'] = 'message';
$handler->display->display_options['relationships']['user']['field'] = 'user';
/* Relationship: Flags: message_viewed */
$handler->display->display_options['relationships']['flag_content_rel']['id'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['table'] = 'message';
$handler->display->display_options['relationships']['flag_content_rel']['field'] = 'flag_content_rel';
$handler->display->display_options['relationships']['flag_content_rel']['required'] = 0;
$handler->display->display_options['relationships']['flag_content_rel']['flag'] = 'message_viewed';
/* Field: Message: Message ID */
$handler->display->display_options['fields']['mid']['id'] = 'mid';
$handler->display->display_options['fields']['mid']['table'] = 'message';
$handler->display->display_options['fields']['mid']['field'] = 'mid';
$handler->display->display_options['fields']['mid']['group_type'] = 'count';
$handler->display->display_options['fields']['mid']['label'] = '';
$handler->display->display_options['fields']['mid']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['mid']['empty_zero'] = TRUE;
/* Contextual filter: Message: User uid */
$handler->display->display_options['arguments']['user']['id'] = 'user';
$handler->display->display_options['arguments']['user']['table'] = 'message';
$handler->display->display_options['arguments']['user']['field'] = 'user';
$handler->display->display_options['arguments']['user']['default_action'] = 'default';
$handler->display->display_options['arguments']['user']['default_argument_type'] = 'current_user';
$handler->display->display_options['arguments']['user']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['user']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['user']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Flags: Flagged */
$handler->display->display_options['filters']['flagged']['id'] = 'flagged';
$handler->display->display_options['filters']['flagged']['table'] = 'flag_content';
$handler->display->display_options['filters']['flagged']['field'] = 'flagged';
$handler->display->display_options['filters']['flagged']['relationship'] = 'flag_content_rel';
$handler->display->display_options['filters']['flagged']['value'] = '0';

```
> 0 votes

---
Tags: 7, rules, views, notifications
---


# Question
Title: How to create entity reference field from custom entity to specific content type
I'm on Drupal 8, using `BaseFieldDefinition::create('entity_reference')` on my custom entity type to add entity reference field;

I also use this `->setSetting('target_type', 'node')` to get nodes but this gives me all nodes of any content type;

Is there any way or possibility to filter these nodes to specific content type?

Here is the code for my field:

```
$fields['project_id'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Project'))
      ->setDescription(t('The project ID, transaction was created for.'))
      ->setSetting('target_type', 'node')
      ->setSetting('handler', 'default')
      ->setTargetEntityTypeId('project')
      ->setDisplayOptions('view', array(
        'label'  => 'hidden',
        'type'   => 'project',
        'weight' => 0,
      ))
      ->setDisplayOptions('form', array(
        'type'     => 'entity_reference_autocomplete',
        'weight'   => 5,
        'settings' => array(
          'match_operator'    => 'CONTAINS',
          'size'              => '60',
          'autocomplete_type' => 'tags',
          'placeholder'       => '',
        ),
      ))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);

```

I want this field to be referenced to Content Type called `project` and not all types of nodes.

# Answer
You're looking for the handler\_settings setting, which provides configuration for the handler you've chosen, in your case, you want:

```
$handler_settings = [
  'target_bundles' => [
    'project' => 'project',
  ],
];

```

As always with fields, widgets and formatters, just create a configurable field in the UI, export it and look at the settings there. You can always copy the settings and other things almost 1:1 from the exported YAML files to a PHP array.
> 10 votes

# Answer
Also you can set it with `->setSetting('handler_settings',['target_bundles'=>['YOUR_CONTENT_TYPE_MACHINE_NAME'=>'YOUR_CONTENT_TYPE_MACHINE_NAME']] )` , you can pass multi value to it. I mean

```
->setSetting('handler_settings',['target_bundles'=>['YOUR_CONTENT_TYPE_MACHINE_NAME1'=>'YOUR_CONTENT_TYPE_MACHINE_NAME1','YOUR_CONTENT_TYPE_MACHINE_NAME2'=>'YOUR_CONTENT_TYPE_MACHINE_NAME2','YOUR_CONTENT_TYPE_MACHINE_NAME3'=>'YOUR_CONTENT_TYPE_MACHINE_NAME3']] )

```

So the final solution for your case is :

```
$fields['project_id'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Project'))
      ->setDescription(t('The project ID, transaction was created for.'))
      ->setSetting('target_type', 'node')
      ->setSetting('handler', 'default')
      ->setSetting('handler_settings',['target_bundles'=>['project'=>'project']] )
      ->setDisplayOptions('view', array(
        'label'  => 'hidden',
        'type'   => 'project',
        'weight' => 0,
      ))
      ->setDisplayOptions('form', array(
        'type'     => 'entity_reference_autocomplete',
        'weight'   => 5,
        'settings' => array(
          'match_operator'    => 'CONTAINS',
          'size'              => '60',
          'autocomplete_type' => 'tags',
          'placeholder'       => '',
        ),
      ))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);

```
> 11 votes

---
Tags: 8, entities
---


# Question
Title: Limit Taxonomy Term references to special vocabulary
I have a custom entity type with custom fields, one of them is an entity\_reference type , I saw this question How to create entity reference field from custom entity to specific content type , and according to it some references I googled , try the below code but it not works .

```
 $fields['book_cat'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Book Category'))
    ->setDescription(t('Book Category Name'))
    ->setSetting('target_type','taxonomy' )
    ->setSetting('handler','default' )
    ->setTranslatable(TRUE)
    ->setDisplayOptions('form', array(
        'type' => 'options_select',
        'weight' => -1,
        'handler_settings' => array(
            'target_bundles'=>['book_cat_agency'=>'book_cat_agency'],
            'size' => '60',
            'placeholder' => '',
        ),
    ))
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayConfigurable('view', TRUE);

```

But not working.

my vocab name is : book\_cat\_agency

# Answer
I see two mistake in your code, first `->setSetting('target_type','taxonomy' )` is mistake and try `->setSetting('target_type','taxonomy_term' )` and try to set `handler_settings` with *setSetting* I mean `->setSetting('handler_settings',['target_bundles'=>['book_cat_agency'=>'book_cat_agency']] )` (although there is a way to set handler\_settings in *setDisplayOptions* )

and finally try following

```
$fields['book_cat'] = BaseFieldDefinition::create('entity_reference')
   ->setLabel(t('Book Category'))
   ->setDescription(t('Book Category Name'))
   ->setSetting('target_type','taxonomy_term' )
   ->setSetting('handler','default' )
   ->setSetting('handler_settings',['target_bundles'=>['book_cat_agency'=>'book_cat_agency']] )
   ->setTranslatable(TRUE)
   ->setDisplayOptions('form', array(
       'type' => 'options_select',
       'weight' => -1,
       'settings' => array(
           'size' => '60',
           'placeholder' => '',
       ),
   ))
   ->setDisplayConfigurable('form', TRUE)
   ->setDisplayConfigurable('view', TRUE);

```
> 0 votes

---
Tags: 8, entities
---


title: How to rereference taxonomy?

text:
# Question
Title: How to rereference taxonomy?
My goal was to create a taxonomy reference field in Drupal 8.2.

Consider these to field definitions on an entity.

```
    // #1
    $fields[$field] = BaseFieldDefinition::create('entity_reference')
        ->setTargetEntityTypeId('taxonomy_term')

    // #2
    $fields[$field] = BaseFieldDefinition::create('entity_reference')
        ->setSetting('target_type', 'taxonomy_term')

```

Here is how #1 is documented:

```
  /**
   * Sets the ID of the type of the entity this field is attached to.
   *
   * @param string $entity_type_id
   *   The name of the target entity type to set.
   *
   * @return $this
   */
  public function setTargetEntityTypeId($entity_type_id) {

```

Looking at the description both should produce the same result - set target entity type.

The #1 creates me an input with autocomplete from page names and page types.

The #2 creates n input with autocomplete from taxonomy terms.

Why does this happen and what is #1 is meant to do?

# Answer
> 1 votes
As I answered at Limit Taxonomy Term references to special vocabulary if you want to create a custom entity\_reference field on custom entity type try something like

```
$fields['book_cat'] = BaseFieldDefinition::create('entity_reference')
   ->setLabel(t('LABEL'))
   ->setDescription(t('DESCRIPTION'))
   ->setSetting('target_type','taxonomy_term' )
   ->setSetting('handler','default' )
   ->setSetting('handler_settings',['target_bundles'=>['VOCAB_MACHINE_NAME'=>'VOCAB_MACHINE_NAME']] )
   ->setTranslatable(TRUE)
   ->setDisplayOptions('form', array(
       'type' => 'options_select',
       'weight' => -1,
       'settings' => array(
           'size' => '60',
           'placeholder' => '',
       ),
   ))
   ->setDisplayConfigurable('form', TRUE)
   ->setDisplayConfigurable('view', TRUE);

```

AND about *setTargetEntityTypeId* :(Doc)

> Sets the ID of the type of the entity this field is attached to.

and used when you want attach field(s) not for referencing.

---
Tags: 8, entities
---


# Question
Title: How to translate the language switcher links
In Drupal 8.1 the language switcher (block can be placed in a region) shows the languages labels in English: English | German | French

I want to translate it. Visiting mysite/de the label should be in German: Englisch | Deutsch | Französisch

mysite/fr --\> labels should be translated in French

The words "German" and "French" and "English" are translated into all languages in my drupal installation. Yet the language switcher shows the labels in English all the way.

How translate it?

# Answer
I'm still looking for this same answer, but there is a way to translate them, so you can have them as English | Deutsch | Français in the language switcher for all languages: just translate the language name on /admin/config/regional/language
> 0 votes

# Answer
Drupal =\> 8.1.10 (Launch sandbox)
**Choose language \>Deutsch (Save and continue)
**  **Choose installation profile \> Standard
Database configuration \> (Save and continue)
Configure website \> (Save and continue)
Update translations
**

**Go to admin/config/regional/language and add English**

**German is the standard language**

**Then edit German: /admin/config/regional/language/edit/de. Change language name from German to De and save.**

**Then edit English: /admin/config/regional/language/edit/en.**
**Change language name from English**

**Got to /admin/config/development/performance and clear cache.**

**Then go to block layout and place the language switcher in any region.**

**Go to the website and check: The language switcher shows De English**
> 0 votes

---
Tags: 8, i18n-l10n
---


# Question
Title: user empties cart how do I redirect that user to originating page
I have a rule

> Redirect to cart after adding a registration

this rule works exactly as planned.

---

New scenario and new rule, If the user empties their cart of all products, I want to redirect to previous page (the sending page).

New rule

> Redirect user to originating page after removing all items from cart

I have the Event and the Conditions but I don't see how to massage the originating address that was used to get to the cart. The originating form action is `<input type="submit" id="edit-submit" name="op" value="Add to cart" class="form-submit">`.

```
{ "rules_redirect_user_to_originating_page_after_removing_all_items" : {
    "LABEL" : "Redirect user to originating page after removing all items from cart",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "Cart" ],
    "REQUIRES" : [ "rules", "commerce_cart" ],
    "ON" : { "commerce_cart_product_remove" : [] },
    "IF" : [ { "data_is_empty" : { "data" : [ "quantity" ] } } ],
    "DO" : []
  }
}

```

Can anyone help?

# Answer
> 1 votes
In your first rule **"Redirect to cart after adding a registration"** you probably are using a **"Page redirect"** action. If so you can do the following.

Edit this action and set "APPEND DESTINATION PARAMETER" to true (see screenshot). This will add the referring page as a query parameter to your url e.g. example.com/cart?destination=node/3

Then in your second rule you can retrieve this destination parameter by using the function drupal\_get\_destination. Use the return value of that function in the drupal\_goto function and the user will be redirected to the url they were coming from.

```
{ "rules_redirect_user_to_originating_page_after_removing_all_items" : {
    "LABEL" : "Redirect user to originating page after removing all items from cart",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "Cart" ],
    "REQUIRES" : [ "php", "rules", "commerce_cart" ],
    "ON" : { "commerce_cart_product_remove" : [] },
    "DO" : [
      { "php_eval" : { "code" : "drupal_goto (drupal_get_destination());" } }
    ]
  }
}

```

# Answer
> 1 votes
using `php_eval` and `drupal_goto` is not good solution ( although you can get drupal\_get\_destination there, but if user remove lineitems on `/cart` what happened ? again redirect to empty cart page ) I suggest Use Page *Redirect to Url* Action and redirect user to your front page or your products page.

```
"DO" : [ { "redirect" : { "url" : "<front>" } } ]

```

---
Tags: 7, commerce, rules
---


title: Add user permission to content node

text:
# Question
Title: Add user permission to content node
I'm creating a collection manager for movies and books in Drupal 8. Now I have a content type called "collection" and one that is called "Movie". The collection is just a collection of different movies. Now I'm searching for a way that a user can give another user access to his collections and movies.

How can I achieve this in my module?

# Answer
Your question looks like a perfect fit for the Group module, which can be used to create collections of content (nodes) that can be accessed by sets of users and with variations of access levels, such as none or read only.

Have a look at the answer to What are the alternatives for the Organic groups module? for a brief introduction to the Group module.

For this specific question, here is a blueprint of how it could be used/configured:

* Group Type: Collections
* Group Roles (refer to "What are the various roles supported by the Group module?" for more details):
    + Group Owner
    + Group Fans (or whatever fits), used for those who have access to a selected collection.
* Groups (adapt the group titles to fit your collection names):
    + Collection 1 of user A.
    + Collection 2 of user A.
    + Collection 1 of user B.
    + Collection 2 of user B.
    + Collection 3 of user B.
    + ...
    + Collection I of user X.
* If a user creates a new group, then automatically assign role "Group Owner"-role to the user who created the group.
* Group permissions: grant permission to the user with role "Group Owner" to perform actions like "Add members" or "Invite members to join".

To use the Group module from within a custom module, start from its Development guide and/or have a look at its API for D7 or API for D8.

# Resources

PS: Even though this question is tagged for D8, this answer applies for either D7 or D8 ...
> 3 votes

---
Tags: 8, users
---


title: image URLs messing up

text:
# Question
Title: image URLs messing up
I recently uploaded my site to a live server and the following issue occurs.

When I add an image to a node and check the url from the admin view it all looks fine and the image displays if I open this very url.

http://example.com/sites/default/files/field/image/cocktail.jpg

However when I view these nodes on the site the images don't appear and the url path changes to

http://example.com/sites/default/files/styles/large/public/field/image/cocktail.jpg

I went into the server and manually created this path (it did not exist before) and uploaded the image. Of course it worked, but I can't expect the client to do this.

Why does it look for the image under a different url in production mode?

I was thinking that it's related to Image Styles. In that case why are the styles actually not created automatically?

# Answer
I get exactly the same problem :
(drupal 7.12 + I use symlinks to a shared code base)

When creating a blog article with an image, the image didn't show up. I check the upload : The image gets uploaded into :
`sites/default/files/field/image/Bienvenue.jpg`
whereas the link points to :
`sites/default/files/styles/large/public/field/image/Bienvenue.jpg` and there was no image at that location...

I double checked permissions which seemed fine (drupal runs as *user* and apache does perform a suPHP).
**However :**
I switched permissions to 777 for folder *default* and all below (except you must not chmod 777 your settings.php file -- for security reason)
and then, after viewing the blog article, the jpg file showed up into : `sites/default/files/styles/large/public/field/image/Bienvenue.jpg`.

I conclude from that :
a) Actually files for displaying images (the ones in `default/files/styles/xxx`) are **created** when first needed
b) permission requested to create these images go beyond 700

I did the test again : permissions 700 and 755 =\> image uploaded, but not displayed permissions have to be 777 to be displayed

Hope it can help you, although it does not explain this permission stuff.
(
i mean : drupal gets enough permissions with 700 for creating in : `sites/default/files/field/image/`
but these same permissions are unsufficient for writing into :
`sites/default/files/styles/large/public/field/image/`
)
> 2 votes

# Answer
I'm getting something very similar in my Dev environment.

I have just added the following code to my template:

```
<?php if(isset($node->field_image['und'])) {
$img = array(
'path' => $node->field_image['und'][0]['uri'],
'width' => '',
'height' => '',
'alt' => $node->field_image['und'][0]['alt'],
'title' => $node->field_image['und'][0]['title'],
);
print theme('image_style', $img);
} ?>

```

Devel indicates that $node-\>field\_image\['und'\]\[0\]\['uri'\] contains

```
public://projects/8xbayshorebus.jpg

```

and the public path for the site is

```
/sites/default/files

```

as one might expect.

This is rendering as

```
src="http://[site]/sites/default/files/styles//public/projects/8xbayshorebus.jpg?itok=[token]"

```

where I expect:

```
src="http://[site]/sites/default/files/projects/8xbayshorebus.jpg?itok=[token]"

```

I have confirmed that http://\[site\]/sites/default/files/projects/8xbayshorebus.jpg exists.

Any idea why this might be happening? (Drupal 7.24)

I copied this code from another content type.

Oddly, that content type is working fine for http but not for https.
> 0 votes

# Answer
I know this is old but i got this problem when i was doing a tutorial exercise to build an Article in Drupal 8.

It occurred to me that what happens is that your uploaded image goes to the designated directory OK but the 'thumbnail' and 'large' versions are generated on the fly, by Drupal, within the Drupal\_root/sites/default/files/styles directory. This act of creation happens the first time they are required.
On my system, Drupal uses the user account "www-data", so that account needs write access to the styles directory to let it create files and directories.

After making that change (chmod), my uploaded image appeared, viola!
> 0 votes

---
Tags: media
---


# Question
Title: Filtered HTML adding two <br> tags, not one
I have a "Filtered HTML" text field and have the convert line breaks to `<br>` & `<p>` tags option turned on in the configuration but when I'm adding content to a "Filtered HTML" field and use Shift + Enter to create a newline within the same paragraph Drupal seems to be adding in two `<br>` tags rather than one, which I'd expect.

For an example the text

```
"I'm having
a great day"

```

gets turned into

```
"I'm having<br><br>
a great day"

```

Is there any way to alter this behaviour to add just one `<br>` tag instead of two?

# Answer
> 0 votes
The only way I've found of resolving this is to replace the two `<br />` tags with one using a `str_replace` in the field preprocess function. I've placed an example below.

```
function theme_preprocess_field(&$vars) {
  switch($vars['element']['#field_name']) {
    // When pressing Shift + Enter in WYSIWYG editor to create a new line it outputs two <br /> tags, not one.
    case "field_description":
      $vars["items"][0]["#markup"] = str_replace("<br /><br />", "<br />", $vars["items"][0]["#markup"]);

      break;
  }
}

```

---
Tags: 7
---


# Question
Title: Files uploaded via custom configuration form are eventually lost
This is a difficult one to explain. so, I am hoping that someone else has had a similar problem. I am uploading a file via custom configuration form, my field on the form looks like:

```
$form['homepage_image'] = array(
  '#type' => 'managed_file',
  '#description' => t('The image used on the home, agents, and featured property pages.'),
  '#default_value' => $config->get('pm_admin.homepage_image'),
  '#upload_location' => 'public://upload/siteimages',
  '#required' => TRUE,
);

```

My submit handler sets the config property in the bog standard way:

```
$config->set('pm_admin.homepage_image', $form_state->getValue('homepage_image'));

```

Initially this all works fine, the image is saved and I can grab it and render it where I want in templates. However, after several hours (I have not figured out the trigger) the image disappears. The configuration form no longer has the value. The file is also removed from the file system.

Not sure what is causing this and would appreciate any help.

# Answer
> 3 votes
The trigger is the 'status' property of the file. It defaults to temporary, and Drupal clears out temporary managed files on a cron run.

To fix, add this to your form's submit method:

```
$fid = $form_state->getValue('homepage_image')[0];
$file = \Drupal\file\Entity\File::load($fid);
$file->setPermanent();
$file->save();

```

---
Tags: 8
---


# Question
Title: How do I exclude admin strings from interface translation?
I want to translate my Drupal 8 site to another language.

I have several translatable strings in my custom theme and modules specified via either the `t` method or `{% trans %}`.

To translate these I have activated interface translation. I can now find my strings by going to `admin/config/regional/translate`.

The problem is this page lists all strings including all strings defined by core. For this project I don't want to translate the admin interface, we specifically want it to stay in the default language (English). This means 90% of the strings listed should not be translated.

I know that I can set the admin interface to stay in a certain language by checking a box on the user account settings page, but this only works when on an admin page. When visiting a node in a translated language, the admin toolbar will still be translated if there are translated strings. If this problem could be solved it would probably be the best solution to just have that box checked.

But for now it seems like my only other option is to only translate the strings I want translated and none of the admin strings. To do this I feel like I have to be able to filter the list of strings on the interface translation page somehow. But there is no way to filter out strings based on which theme or module they are defined in. Or is there?

I have seen that there is a context parameter you can pass to the `t` method or `{% trans %}`. Maybe if I add a key like "translate" or something here, I could filter out strings with this context and only translate them. The thing is it feels like using the context parameter in the wrong way and it does not seem to be any way to filter by context either.

Does anyone have a good solution for this?

# Answer
> 3 votes
There is no solution that I'm aware of. You can't change the context of strings in core or contrib modules without changing the code. Which you shouldn't do.

The fact that toolbar doesn't show the english strings if your admin language is english is a big that's trying to be fixed here: https://www.drupal.org/node/2313309

I don't know if that's still doable in 8.x.

# Answer
> 0 votes
We needed to cater for this use case as well, in particular for landing page content and pages based on twig template overrides/suggestions.

Our solution was to create a new Twig extension called `tr`.

The class of the extension plugin checks to see if a 'translations' directory exists in the current theme. If it does, it reads the containing YAML translation files into an associative array (en.yml, es.yml, fr.yml etc.)

When `{{ tr('source string') }}` is called in the twig template, it will check the loaded associative arrays to see if there is a translation available for the current language and requested string. If there is it will return the translated value.

This works for us since in our case we're only translating a fairly short list of values - short strings and labels like 'Read More', 'Learn More', 'Subscribe' etc. The rest of our translated content comes from the content translation of the entities.

Hope this helps...

---
Tags: 8, i18n-l10n
---


# Question
Title: Twig Translation String without Enabling Interface Translation
Is it possible to provide translation strings to Twig, without the Interface Translation module enabled?

We have Content Translation enabled but do not want to enable Interface translation (we would like the Drupal administration menu system to remain in English).

We have a couple of landing pages that base most of their content on a translated entity however, there are still a few labels and links we would like to translate using {{ 'foo'|t }} in Twig.

Is this possible? And if so - where would the translation stings be stored?

# Answer
Our solution in the end was to create a new Twig extension called `tr`.

The class of the extension plugin checks to see if a 'translations' directory exists in the current theme. If it does, it reads the containing YAML translation files into an associative array (en.yml, es.yml, fr.yml etc.)

When `{{ tr('source string') }}` is called in the twig template, it will check the loaded associative arrays to see if there is a translation available for the current language and requested string. If there is it will return the translated value.

This works for us since in our case we're only translating a fairly short list of values - short strings and labels like 'Read More', 'Learn More', 'Subscribe' etc. The rest of our translated content comes from the content translation of the entities.

Hope this helps...
> 3 votes

---
Tags: 8, i18n-l10n
---


# Question
Title: How is AJAX attached to exposed filters?
I am currently rendering a view manually like so:

```
$content = \Drupal::service('renderer')->renderPlain(views_embed_view('user_admin_people', 'page_1'));

```

Then I'm sending the html to the page and inserting it into a div with javascript. I needed to use `renderPlain()` rather than `render()` because when I was doing that, I was getting this error:

> LogicException: Render context is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use renderPlain()/renderRoot() or #lazy\_builder/#pre\_render instead.

Now, you're probably thinking, why don't you just use render arrays normally and let Drupal handle it? Unfortunately, I can't do that, I need to render the view's html and send it to the page, which I have already done. BUT, when I do this, clicking on 'Filter' brings me to the /admin/people page of the Drupal site (on which it will do ajax filters properly, because it rendered from a normal render array).

How could I attach the javascript to this view html so that it reloads its data via ajax instead of linking me to the view's page? I have already tried Drupal.attachBehaviors(), thinking that it would run something from ajax\_view.js from views (which is a confusing & large file).

Or, where would I look in core to find out more about this, or where is some good documentation to read? Am I looking in the right place in core, looking at ajax\_views.js?

# Answer
> 1 votes
Still early rendering should be avoided whenever possible. Did you try to return the unrendered view in an ajax command?

```
  $view = views_embed_view('user_admin_people', 'page_1');
  $ajax_response->addCommand(new HtmlCommand('#wrapper', $view));

```

If you use the unrendered build array all the things you've described in the question like reattaching drupal behaviors, js, and css are handled by the ajax implementation in drupal, on the server side when assembling the response and on the client side when processing the incoming json data.

For this to work you also need to enable the option "Use AJAX" in the view `user_admin_people`, otherwise the "Filter" button rebuilds the form on a new page, which then happens to be the admin page.

---
Tags: 8, views
---


# Question
Title: Can i use route ID for Link template 'edit-form' for entity type?
Can i use route ID for Link template 'edit-form' for entity type?

I'm following this tutorial

over there he use:

```
 *   links = {
 *     "edit-form" = "flower.edit",
 *     "delete-form" = "flower.delete"
 *   }

```

while flower.edit (i assume) is from below route.yml:

```
flower.edit:
  path: '/admin/structure/flowers/edit/{flower}'
  defaults:
    _entity_form: 'flower.edit'
    _title: 'Edit flower'
  requirements:
    _permission: 'administer site configuration'

```

but when i run, it throw me an error:

> Uncaught PHP Exception Drupal\Core\Entity\Exception\InvalidLinkTemplateException: "Link template 'edit-form' for entity type 'flower' must start with a leading slash, the current link template is 'flower.edit'" at \core\lib\Drupal\Core\Entity\EntityTypeManager.php line 97

I know i can just use: `/admin/structure/flowers/edit/{flower}` to solve my problem.

but the question is: is it actually possible to use route (instead of path) in entity links config?

# Answer
The tutorial is from 2014. Since then the link templates have changed from route to path. See change record:

**Previous link template format**

```
   links = {
     "canonical" = "entity.node.canonical",
     "edit-form" = "entity.node.edit_form",
     "delete-form" = "entity.node.delete_form",
   }

```

**New link template format**

After the change, the path is used.

```
   links = {
     "canonical" = "/node/{node}",
     "edit-form" = "/node/{node}/edit",
     "delete-form" = "/node/{node}/delete",
   }

```
> 2 votes

---
Tags: 8, entities
---


# Question
Title: How to access individual theme settings from code?
I was building a block for which I have to provide bubblable metadata. The data in this block is depending on individual theme configurations as well as the global theme settings.

So I tried the following:

```
$config = \Drupal::config('system.theme.global');
$bubbleable_metadata->addCacheableDependency($config);

$config2 = \Drupal::config('bartik.settings');
$bubbleable_metadata->addCacheableDependency($config2);

```

This however obviously does not work if the theme is not set to bartik. I have been attempting to find the theme configuration in `\Drupal::theme()->getActiveTheme()`, but that does not provide this data.

I suppose I could try `$config = \Drupal::theme()->getActiveTheme()->getName() . '.settings';`, but I'd like to learn if there are better ways.

How to get the configuration (or config name) of the current active theme?

# Answer
> 2 votes
It seems this is actually the recommended way. It is used in `theme_get_settings()` as well:

```
$theme = \Drupal::theme()->getActiveTheme()->getName();
...
  if ($theme_settings = \Drupal::config($theme . '.settings')->get()) {
    ...
  }

```

---
Tags: 8
---


# Question
Title: Facebook comments box for site loading very slowly
Hi I'm using a Facebook comments module for my Drupal 6 website on aws.

I've noticed that especially during mobile visits the loading of the Facebook comments box is last and is slowing down the page load time.

How do I find out if this comment Facebook code is loading asynchronously and how to speed it up? Any way to update the Facebook comments module?

Thanks!

# Answer
Connect your phone's browser to the Developer Tools on your computer. Check the network tab and check what's slowing down the requests.

It might be that you have too many requests, and the comment requests are being given a lower priority in order to render the actual page first.

Here are the links for Android and iOS

https://developers.google.com/web/tools/chrome-devtools/remote-debugging/

https://developer.apple.com/library/content/documentation/AppleApplications/Conceptual/Safari\_Developer\_Guide/GettingStarted/GettingStarted.html

For Apple's link, go down to the section named '*Safari on iOS*'

---

Safari's network tab

Chrome's network tab
> 1 votes

---
Tags: social-network
---


# Question
Title: Trigger a module function after a node is saved or updated successfully in the database
I have used this function `hook_node_insert()` , but it does not help me because this hook runs before the node is actually saved in the database. I am indexing nodes to a third party application whenever a node is inserted, updated or deleted. The application sends request to the node URL, but using `hook_node_insert()`. It's giving me an invalid document location error because the node is not actually inserted yet.

Is there any hook invoked after a node is saved or updated in the database?

I followed this approach, without success.

```
function  my_module_node_insert($node) {
  if (!$node->type == 'article' || !$node->type == 'page') {
    return;
  }
  my_module_do_index($node);
}

```

# Answer
> 1 votes
You may be able to use Hook Post Action and then use this hook:

```
function my_module_node_postinsert($node) {
  if(!$node->type == 'article' || !$node->type == 'page' )
      return;
  my_module_do_index($node) ; // indexes the node
}

```

Give it a try and see if it helps!

The project link: https://www.drupal.org/project/hook\_post\_action

# Answer
> 0 votes
> What you can do then is register a function with Drupal that will get called just about when Drupal is finished with the request. It's actually very simple. You just call `drupal_register_shutdown_function()` with the name of the function you want to be called. Additionally, you can pass as further arguments whatever it is in your context you want passed to it. It's kinda like subscribing a function to an event.
>
> So now when the request is finishing, we know the `node_save()` database transaction has completed and we can rely on the data from the database. Using `path_load()` now will guarantee that the latest path for that node is being loaded.

Source: Drupal 7 post insert hooks as a shutdown function - https://www.webomelette.com/drupal-7-post-insert-hooks-shutdown-function

# Answer
> -1 votes
What you want to use is this function

hook\_entity\_insert($entity, $type)

This function is called after the hook\_node\_insert and trigger your my\_module\_do\_index( $node )

Same with the update function use hook\_entity\_update instead.

Other way to do it could be via hook\_cron() and update your index with the cron system.

---
Tags: 7, nodes
---


# Question
Title: How to select state on country bases in drupal webform
How to select the state on country bases in drupal.I have different country and states now I want to select the state on the country bases. I have installed the webform module and webform conditional field module. How I can do this task.

# Answer
> 2 votes
Use the Webform Simple Hierarchical Select and the Simple hierarchical select modules; just create a vocabulary and add countries and states hierarchically.

If you don't have vocabularies for countries and states, using the Taxonomy Manager module helps you to import countries and states from a simple list like the following.

```
United Stated
- Alabama
- Washington
Iran
- Tehran
India
- Mbambi

```

# Answer
> 1 votes
You can use a combination of the Webform Simple Hierarchical Select and the Simple hierarchical select modules. In this way, you can make the latter module work with the Webform module.

If you need a list of countries/states, you can get it from Lists of Options. This is a tutorial on how to import a list of countries/states into your vocabularies using the Taxonomy CSV Import Export module.

---
Tags: webforms
---


# Question
Title: How do I add a JavaScript file from a module?
```
$form['set_end_date'] = array (
  '#type' => 'date',
  '#title' => t('set end date'),
  '#required' => TRUE,
);

$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
  '#type' => 'submit',
  '#value' => $this->t('Fetch'),
  '#button_type' => 'primary',
);
return $form;

```

How do I add a JavaScript file from a module?

# Answer
You will have to add the js in libraries.yml, like

```
dirty_forms:
  version: VERSION
  js:
    js/jquery.dirtyforms.js:{}
dirty_forms_ckeditor:
  version: VERSION
  js:
    js/jquery.dirtyforms.ckeditor.js:{}

```

and then include in the form via

```
$form['#attached']['library'][] = 'dirty_forms/dirty_forms';
```
> 2 votes

---
Tags: javascript
---


# Question
Title: What do I do after I merge feature files with a remote server?
I'm having real trouble getting my head around the Features module. Would someone be able to help me understand it a little better? Perhaps describe it in laymans terms?

Here's the scenario I am working on right now:

I've made a change to some mini-panel and want to move those changes to a remote server with Features.

I create that feature and add the mini-panel and download the files. This part seems fine - I can even view my changes in the file's code. I then merge these files onto my remote server.

It's here I get a bit stuck. Now what do I do?

When I find my Feature in /admin/structure/features it's overridden. What do I do next to update my mini-panel on the remote server?

# Answer
> 2 votes
You will have to revert the feature, So that the configurations in the remote server would be same as that in the code. Feature overridden means, the config in the Code and that in the server is not the same. So by reverting the feature you make the code and the db config the same. Please be cautious while reverting the feature, Sometimes the changes which you have done directly in the server would be lost. It'd be best if you test reverting the feature in your staging environment first.

---
Tags: 7, features
---


title: Breadcrumb with taxonomy path

text:
# Question
Title: Breadcrumb with taxonomy path
*I use the theme "Bootstrap".*

When I display a node, there is no breadcrumb. My nodes are related to taxonomy terms.

On the screenshots :

> Boutique / Les chocolats BIO

The second screenshot should be :

> Boutique / Les chocolats BIO / Tablette de chocolat noir artisanale BIO aux épices tchaï

"Boutique" is the vocabulary of taxonomy and "Les chocolats BIO" is the terms of taxonomy.

How to display the breadcrumb on the nodes without using any additional modules ?

# Answer
you can implement hook\_node\_view and make alterations in the breadcrump eg:

```
/*
 * Implements hook_node_view().
 */
function my_custom_module_node_view($node, $view_mode) {
  if ($node->type == 'my-node-type') {
    $type == $node->field_test_field['und'][0]['value'];
    if ($type == 0) {
      $breadcrumb = drupal_get_breadcrumb();
      $breadcrumb[1] = 'new breadcrumb';
      drupal_set_breadcrumb($breadcrumb);
    }
  }
}

```
> 1 votes

---
Tags: 7, theming, nodes, taxonomy-terms
---


# Question
Title: "Class 'PHPMailer' not found in /home/mysite/www/sites/all/modules/phpmailer/includes/phpmailer.class.inc on line 12"
I tried to work on my security parameters on drupal... I went into the security page on drupal and chmod 664 the following folders: themes, modules, cache, site, profiles and include. Simultaneously, i also turned off messages display. And i configured my site address in the settings file.

When i tried to update everything to check out the settings, a fatal error prevented me to access my website. User\_class was not accessible. So i went into my MYSQL database and turned to 1 the user module. Now, the message is:

> Fatal error: Class 'PHPMailer' not found in /home/mysite/www/sites/all/modules/phpmailer/includes/phpmailer.class.inc on line 12

I updated my website, but doesn't work.

Here is what i get:

```
Call Stack

1   0.0005  236608  {main}( )   ../index.php:0
2   0.0186  654760  drupal_bootstrap( ) ../index.php:20
3   0.2480  6656728 _drupal_bootstrap_full( )   ../bootstrap.inc:2278
4   0.9109  25055992    module_invoke_all( )    ../common.inc:5193
5   0.9650  26510896    call_user_func_array ( )    ../module.inc:895
6   0.9651  26511064    mailsystem_init( )  ../module.inc:895
7   0.9651  26511104    mailsystem_get_classes( )   ../mailsystem.module:17
8   0.9854  26938376    class_exists ( )    ../mailsystem.module:306
9   0.9854  26938672    drupal_autoload_class( )    ../mailsystem.module:0
10  0.9854  26938720    _registry_check_code( ) ../bootstrap.inc:3103
11  0.9883  27012760    require_once( '/home/mysite/www/sites/all/modules/phpmailer/includes/phpmailer.class.inc' ) ../bootstrap.inc:3179

```

i explored the web, no real answer... I did a chmod - r 777 to all the files i chmod. Of course, phpmailer is well set up...

Update: i tried `drush en -y menu` and here is the answer:

```
root@ns333613:/home/mysite/www# drush en -y menu
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/ming.ini on line 1 in Unknown on line 0
array_keys() expects parameter 1 to be array, null given common.inc:7102                        [warning]
array_keys() expects parameter 1 to be array, null given common.inc:7102                        [warning]
PHP Fatal error:  Call to undefined function menu_get_menus() in /home/mysite/www/sites/all/modules/xmlsitemap/xmlsitemap_menu/xmlsitemap_menu.module on line 37
PHP Stack trace:
PHP   1. {main}() /usr/share/php/drush/drush.php:0
PHP   2. drush_main() /usr/share/php/drush/drush.php:16
PHP   3. _drush_bootstrap_and_dispatch() /usr/share/php/drush/drush.php:61
PHP   4. drush_bootstrap_to_phase() /usr/share/php/drush/drush.php:81
PHP   5. drush_bootstrap() /usr/share/php/drush/includes/bootstrap.inc:308
PHP   6. _drush_bootstrap_drupal_login() /usr/share/php/drush/includes/bootstrap.inc:185
PHP   7. drush_drupal_login() /usr/share/php/drush/includes/bootstrap.inc:979
PHP   8. user_load() /usr/share/php/drush/includes/drupal.inc:138
PHP   9. user_load_multiple() /home/mysite/www/modules/user/user.module:366
PHP  10. entity_load() /home/mysite/www/modules/user/user.module:291
PHP  11. entity_get_controller() /home/mysite/www/includes/common.inc:7849
PHP  12. entity_get_info() /home/mysite/www/includes/common.inc:7883
PHP  13. drupal_alter() /home/mysite/www/includes/common.inc:7719
PHP  14. xmlsitemap_menu_entity_info_alter() /home/mysite/www/includes/module.inc:1101

Fatal error: Call to undefined function menu_get_menus() in /home/mysite/www/sites/all/modules/xmlsitemap/xmlsitemap_menu/xmlsitemap_menu.module on line 37

Call Stack:
    0.0013     254960   1. {main}() /usr/share/php/drush/drush.php:0
    0.0767    2486840   2. drush_main() /usr/share/php/drush/drush.php:16
    0.6131    6590152   3. _drush_bootstrap_and_dispatch() /usr/share/php/drush/drush.php:61
    0.9727    6595496   4. drush_bootstrap_to_phase() /usr/share/php/drush/drush.php:81
    2.1957   37568016   5. drush_bootstrap() /usr/share/php/drush/includes/bootstrap.inc:308
    2.1991   37569712   6. _drush_bootstrap_drupal_login() /usr/share/php/drush/includes/bootstrap.inc:185
    2.1996   37569944   7. drush_drupal_login() /usr/share/php/drush/includes/bootstrap.inc:979
    2.1996   37570128   8. user_load() /usr/share/php/drush/includes/drupal.inc:138
    2.1996   37570648   9. user_load_multiple() /home/mysite/www/modules/user/user.module:366
    2.1996   37570728  10. entity_load() /home/mysite/www/modules/user/user.module:291
    2.1996   37570792  11. entity_get_controller() /home/mysite/www/includes/common.inc:7849
    2.1997   37571320  12. entity_get_info() /home/mysite/www/includes/common.inc:7883
    2.2434   37671552  13. drupal_alter() /home/mysite/www/includes/common.inc:7719
    2.2652   37680800  14. xmlsitemap_menu_entity_info_alter() /home/mysite/www/includes/module.inc:1101

Drush command terminated abnormally due to an unrecoverable error.                              [error]
Error: Call to undefined function menu_get_menus() in
/home/mysite/www/sites/all/modules/xmlsitemap/xmlsitemap_menu/xmlsitemap_menu.module, line 37
                                                                                [error]
Drush was not able to start (bootstrap) Drupal.
Hint: This error can only occur once the database connection has already been successfully
initiated, therefore this error generally points to a site configuration issue, and not a
problem connecting to the database.

Drush was attempting to connect to:
 Drupal version                  :  7.34
 Site URI                        :  http://default
 Database driver                 :  mysql
 Database username               :  phpmyadmin
 Database name                   :  mysite
 Database                        :  Connected
 Default theme                   :  open_framework
 Administration theme            :  bartik
 PHP executable                  :  /usr/bin/php
 PHP configuration               :  /etc/php5/cli/php.ini
 PHP OS                          :  Linux
 Drush version                   :  6.2.0
 Drush configuration             :
 Drush alias files               :
 Drupal root                     :  /home/mysite/www
 Site path                       :  sites/default
 File directory path             :  sites/default/files
 Temporary file directory path   :  /tmp

```

---

After lots of search, and no more clues, i decided to creat a new folder on my server and start again from zero. I re installed drupal, with a new database, like usual...Fine ! i changed my settings to connect my new site to my old database...And the same issue is back ! So i guess this might come from something wrong in my database. I turned to 0, the phpmailer in the system table: both bootstrap and module status...But still nothing works

# Answer
> 1 votes
This might be an issue with a cached phpmailer path that will error out before you can run a `drush cc all`, so give this a go:

Open your includes/bootstrap.inc file.

Add these two lines at the top, replacing "path-to-your-site" with your site's path:

```
set_include_path(get_include_path() . PATH_SEPARATOR . '/path-to-your-site/sites/all/libraries/phpmailer');
require_once('class.phpmailer.php');`

```

Run `drush cc all` \- it should work without errors now.

Finally, remove those lines from includes/bootstrap.inc - and your site should load.

# Answer
> 0 votes
By setting all those folders to 664, you've removed the ability for the server to use the files.

The folders you listed should be 755.

# Answer
> 0 votes
I, too, ran into the "PHPMailer Class not found" issue. The immediate symptom was a WSOD, and when I tried to run "drush cc all" I got the "PHPMailer class not found error" described by Ryan. AHeath's suggestion above \[to modify my bootstrap.inc file to force inclusion of 'class.phpmailer.php'\] allowed me to run drush cc all, and then *leaving in the additional bootstrap statements* to bring my site up. Subsequently, I took out the two additional php statements and everything seems normal now.

My contribution to this discussion is that just before I got the WSOD I had disabled the PHPMailer and smtp authentication modules. The sequence was (1) disable the two modules, and then, (2) get a WSOD and the inability to run drush.

It is not strictly germane to the issue here, but the reason I had disabled the modules was that I wanted to see if the new virtual server I am using would be able to send drupal e-mail without those two modules.

I still have no idea why disabling those 2 modules would give me all the trouble that it did, but I did do a little extra investigating and found that the PHPMailer class is defined in at least two places: in the smtp.phpmailer.inc file in the smtp module, and in the class.phpmailer.php file in the phpmailer library. I also noticed that the class.phpmailer.php file is commented out in the PHPMailer module's .info file. I wonder if when I disabled the smtp module, I also removed the only place that the PHPMailer class was defined, and that that caused all of my subsequent difficulties.

# Answer
> 0 votes
It seems your problem is because of file permission, The Drupal files folder should be writable by the web server. The safest way to do that is to change the group and make it group writable, like this:

```
chgrp www-data sites/default/files
chmod g+w sites/default/files

```

The file upload folder aside, the safest is chmod 644 for all files, 755 for directories.

This could be accomplished like this (when run in the Drupal-site folder, the `.` is for current path):

```
find . -type f | xargs chmod 644
find . -type d | xargs chmod 755

```

Remember that you will need to set `chmod g+w` again after running the above command, since those will reset the chmod on all files and folders.

---
Tags: bootstrapping
---


# Question
Title: would like to replace node contents with pdf under some conditions
I have been using hook\_node\_view to set the node contents depending on a bunch of things - this works well except when I need to replace the entire page with a pdf. The hook function looks something like

```
function gcc_event_node_view($node, $build_mode = 'full') {
if ($node->type !== 'eventlist') {
    return;
}
if (have replacement html) {
    $node->content['body'][0]['#markup'] = "new stuff";
} else if (use pdf) {
    header('Content-type: application/pdf');
    header('Content-length: ' . filesize($fullPath));
    header('Content-Disposition: filename=' . $this->ShortName() . $file);
    readfile($fullPath);
   // need something here to make the node not render further at all
}

```

Appreciate all suggestions on the right way to do this. Should be able to do images with image/jpg as well.

# Answer
> 0 votes
If you have to replace the entire page content, then you will have to alter the page.tpl.php conditionally, You can implement hook\_preprocess\_page for checking for node id or node type, Then modify the content printed in page.tpl.php.

---
Tags: media, files
---


# Question
Title: Page cache not rebuilding after page cache maximum age is reached
I have a pretty minimal Drupal 8 install with some views blocks that show upcoming event node links. I've noticed that once an event is passed they still show up and it is because the pages of my site are cached. However, I set the "Page cache maximum age" on the performance page to 6 hours and Drupal continually caches pages for days or weeks. I have to manually click clear all caches before the site will update. Cron is also setup and running regularly without a problem. I thought maybe that triggered the cache rebuild but I've set it to 6 hours, 12 hours, 3 hours, etc. with no result.

I'm not sure why this is happening. I'm not doing anything else to cache, no other modules or server programs like Varnish or anything.

# Answer
The *Internal Page Cache* for anonymous users doesn't use any configuration option. If you want a quick solution in UI your only chance is to de-install this module.

Better for performance is to set an expiration time for the cached pages, but for this you need custom code, see this answer Anonymous user cache control.

In both cases the setting on the performance page is still necessary to set the correct headers for external caches.
> 1 votes

---
Tags: 8, caching
---


# Question
Title: How to unset field in views conditionally
I'm using `hook_views_pre_render()` in a module to make sure an image field `'field_field_company_logo'` is removed for a certain content type `'job_listing'`. I have the following code, which works, but produces warnings:

```
function hideviewsfields_views_pre_render(&$view) {
  if ( ($view->name == 'job_search') && ($view->current_display == 'job_search_results') ) {
    $result = $view->result;
    foreach ($result as $row) {
      $type = $row->_field_data['nid']['entity']->type;
      if ( $type == 'job_listing' ) {
        unset ( $row->field_field_company_logo );
      }
    }
  }
}

```

It works, in as much as the correct images are omitted, but I get the following warnings:

```
Notice: Undefined property: stdClass::$field_field_company_logo in views_handler_field_field->get_items() (line 715 of /public_html/sites/all/modules/views/modules/field/views_handler_field_field.inc).
Warning: Invalid argument supplied for foreach() in views_handler_field->advanced_render() (line 1053 of /public_html/sites/all/modules/views/handlers/views_handler_field.inc).
Notice: Undefined property: stdClass::$field_field_company_logo in views_handler_field_field->get_items() (line 715 of /public_html/sites/all/modules/views/modules/field/views_handler_field_field.inc).
Warning: Invalid argument supplied for foreach() in views_handler_field->advanced_render() (line 1053 of /public_html/sites/all/modules/views/handlers/views_handler_field.inc).

```

I've seen elsewhere people writing code similar to the following:

```
unset($view->field[$field_name]);
unset($view->display_handler->handlers['field'][$field_name]);

```

where the first line seems similar to the unset I am executing, but I believe it was acting upon a different variable (i.e. not $views -- maybe $data?) and I can't find any other reference to the image field within the $view object that can be unset without it removing it altogether from the display.

# Answer
Drill down in the field\_field\_company\_logo field to its \['rendered'\]\['#access'\] property and set it's value to FALSE.
> 4 votes

# Answer
I was trying to hide/unset field in **Drupal 8** but the above approach was not working so I used following code to hide/unset field in Views result page (**D8**),

```
function hideviewsfields_views_pre_render(ViewExecutable $view) {
  if ($view->id() == 'job_search') {
    foreach ($view->field as $key => $value) {
      if ($key == 'field_company_rating') {
        $value->options['exclude'] = TRUE;
      }
    }
  }
}

```
> 1 votes

---
Tags: views
---