How to send uploaded file as a link in entityform submission I am using entityform for getting the user details. The entityform also contains a file field where user uploads resume. After the submission user gets the submitted form via email.

How to send the link of the uploaded file in an email to user.

Thank you.

How are you sending the mail?

You can try using https://www.drupal.org/project/mimemail and just insert the image in your mail


Make field editable in comment form Could you please help me with the following task? I need to make the existing field (name Clarify, type select - "clarification required/clarification isn't required") to be editable from display view (not on the Edit tab) and I need to place this field next to Comment field (see the screenshot).

I'm trying to use hook_alter_form in the following way, but with no luck. I know the below code is wrong and I need a little help to know which way to go.

function custom_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'comment_node_support_ticket_form') {
    $form['field_clarify'] = array(
      '#type' => 'select',
      '#title' => 'Clarify',
    );

    $form['#validate'][] = 'custom_support_comment_submit';
  }
}

function custom_support_comment_submit($form, &$form_state) {
  $node = node_load($form_state['values']['nid']);
  $node_wrapper = entity_metadata_wrapper('node', $node);
  $node_wrapper->field_clarify->set($form_state['values']['field_clarify']);
  $node_wrapper->save();
}

First, you need 'options' => array('clarification required', 'clarification isn\'t required') for select because you need options. Then you need to make sure your module name is custom (unless you don't want to expose your module name). Also, you pass your function name to $form['#validate'][] but it ends with _submit (it should be _validate).

There are what I found at the first glance. I didn't check the code.


How to link menu item to a page in Drupal7, that can display database content? I am using a custom module in my Drupal7 to add data in a form and then inserting it into the database. The form has fields like "Menu Name", "Image", etc. I want to know :

How can i show this dynamic content in my site, by clicking on each of the menu items?
In other words, how to link dynamic content to the menu items? The name of the menu item will be equal to one of the fields (Menu Name) in the form in my custom module. Each of the menu item pages can have a different design & layout (based on form data).

Do i need to hack my page.tpl.php?

Do i need to create as many .tpl pages as those of menu items for showing the dynamic content?
I just want to know What is the best way to achieve this.

There are 3 broad ways of doing this i) create a widget ii) ajax/json iii) create a block.

The widget method is suitable if you are trying to create an element in the form that is more sophisticated than the form elements provided. You present it in a node--contenttype.tpl.php template. Replace 'contenttype' with the name of the content type you created.

If you want to print out just parts of the data captured in the form then you can use hide($content['fieldname') to get rid of any fields that you don't want rendered. That is the 'streamlined' way. See the 'field example' module in the examples project.

Assuming the module is called ognotify you will need to implement:

ognotify_field_info() to declare the field
ognotify_field_widget_info to define the widget and
ognotify_field_formatter_info() to define the available formats.

These 3 things define the 'edit content type form' in the administration area of drupal.

To process the output you also need to implement

ognotify_field_is_empty($item, $field)
ognotify_field_widget_form(&$form, &$form_state, $field, $instance,
$langcode, $items, $delta, $element) to define the form elements

and some validation routines. You can add this 'widget' to any content type.

It sounds as though you are trying to render something more specific. If by dynamic you mean via ajax then one way is to create an ajax block and callback response from the block (module is called bookreview this time).

Define the block as per:

function bookreview_block_display($delta, $args) {
...

This calls a form element of ajax type.

function _bookreview_publish_review_link($args) {
  $block = array();
  if (empty($args['nid']) || empty($args['status'])) {
    return $block;
  }

  $block['content'] = array(
    '#type' => 'link',
    '#title' => 'Publish review',
    '#href' => 'bookreview/publish/' . $args['nid'],
    '#prefix' => '
',
    '#suffix' => '
',
    '#ajax' => array(
    'effect' => 'fade',
    ),
 );

 ...
  return $block;
}

Render this on a page. You can do this by mapping blocks, or in code in a template:

$block = module_invoke('bookreview', 'block_display', 'bookreview_publish_review_link', $args);
print render($block['content']

The callback in this example is 'bookreview/publish'. This is the 'access content from a menu' solution. Implement the menu:

function bookreview_menu() {
  $items = array();
  $items[BOOKREVIEW_MODULE_NAME . '/publish/%node'] = array(
    'title' => 'Publish a Book Review',
    'page callback' => 'bookreview_publish_review',
    'page arguments' => array(2),
    'access callback' => 'bookreview_access_callback_check',
    'access arguments' => array(array(BOOKREVIEW_ADMIN_PERMISSION_NAME)),
    'type' => MENU_CALLBACK,
    'file' => 'includes/BookReviewEvents.php',
  );
  return $items;
}

Now we have mapped a menu item (uri) to a function that prints out the content.

function bookreview_publish_review($node) {
  if (!isset($node)) {
    return;
  }

This takes a node argument, %node in the menu definition which automatically gets converted from a node number to a node loaded from the database. The address publish/123 will result in node 123 being passed to your function. You can create a callback for each of the fields in the content type as per /bookreview/menu-name-field/%node. Then create a function to either directly print out the ajax json response:

...
// How you want to get the data from the node. Best to use Netbeans/php debugger
// or dpm() if you don't have it.
$menu_name_field_data = $this->node->{$this->_findMenuFieldName()}[LANGUAGE_NONE][$delta]['value'];
$data_to_print[] = $menu_name_field_data;
ajax_deliver(array('#type' => 'ajax', '#commands' => $data_to_print));
...

The 3rd way is similar to creating the ajax response, except that you define a block that allows you to render the html content. As per the ajax defining a menu item and declaring a block. You print out the content there instead of defining an ajax form.

The widget answer is the most reusable, the ajax answer is the most dynamic and flexible and the block method presents HTML instead of ajax responses. Regarding 'dynamic' the ajax solution best meets your description in the question, although I thought it necessary to present the breadth of the possibilities so that you can make choices regarding the tradeoff between reuse and dynamic.


Moving functions in block module to inc file I have searched everywhere for an answer to this question, and have found little to no help on the subject.

The closest question to my own would be this, but the answer for it is a bit different than what I'm looking for:
How to move block functions into .inc file?

Here is my code for the most part (everything removed that wasn't necessary):

<?php

function custom_giggity_block_info(){
  $block['custom_giggity'] = array(
    'info' => t('Custom giggity'),
    'cache' => DRUPAL_NO_CACHE,
  );
  return $block;
}

function custom_giggity_block_view($delta = ''){
  $block = array();
  if($delta == 'custom_giggity'){
    $block['content'] = custom_giggity_contents($delta);
  }
  return $block;
}

function custom_giggity_contents($delta){
  //Code that generates what goes into $block['content']
  return $output;
}

And I need to use something like this, and don't know how to incorporate it:

function giggity_contents() {
  $items['giggity'] = array(
    'title' => "Giggity",
    'page callback' => "show_giggity", //or custom_giggity_contents ;)
    'access arguments' => array('access content'),
    'file' => 'giggity.inc',
    'type' => MENU_CALLBACK
  );
  return $items;
}

Now I realize that the second block of code there might completely off, but I'm just using it as an example as to what I need to accomplish.

Edit: So this is what I'd like to accomplish, but I'm not sure how the $items callbacks work. I took this piece of code from a hook_menu() and replaced it with giggity_contents.

<?php

function custom_giggity_block_info(){
  $block['custom_giggity'] = array(
    'info' => t('Custom giggity'),
    'cache' => DRUPAL_NO_CACHE,
  );
  return $block;
}

function custom_giggity_block_view($delta = ''){
  $block = array();
  if($delta == 'custom_giggity'){
    $block['content'] = giggity_contents($delta);
  }
  return $block;
}

function giggity_contents() {
  $items['giggity'] = array(
    'title' => "Giggity",
    'page callback' => "custom_giggity_contents",
    'access arguments' => array('access content'),
    'file' => 'giggity.inc',
    'type' => MENU_CALLBACK
  );
 return $items;
}

giggity.inc file:

 function custom_giggity_contents($delta){
  //Code that generates what goes into $block['content']
  return $output;
 }

Like tenken said, use include_once at the top of the ".module" file like this:

<php
include_once drupal_get_path('module', 'module_name') . '/module_name.functions.inc';
?>


Add new variable in Computed field Can I add new variable in Computed field?
The added variable will be used only in the computed field

Yes you can

Computed Field is a very powerful field module that lets you add a custom "computed
fields" to your content types.

  These computed fields are populated with values that you
      define via PHP code.


How can I get the current node view mode and add to block template suggestion? In my code, I need to get the current view mode of the node to be able to pass it to be used as a block template suggestion.

The function I have set up is able to grab all available view modes, but I just want the current one. Possibly a condition that I haven't come across yet would do the trick?

function mytheme_theme_suggestions_block_alter(array &$suggestions, array $variables) {
// Add template suggestions based on the current view mode and node type.
  if ($node = \Drupal::routeMatch()->getParameter('node')) {

   $view_modes = Drupal::entityQuery('entity_view_mode')
   ->condition('targetEntityType', 'node')
   ->execute();

   foreach ($view_modes as $view_mode) {
   $view_mode = str_replace('node.', '', $view_mode);
   $suggestions[] = 'block--' . $node->getType() .'-'. $view_mode;
  }
 }
}

You say in your comment it is not useful for you and I doubt there are many use cases for this at all, because normally as main content a node is rendered in the full view mode.

Nonetheless trying to answer: A block is built based on contexts and at the moment this is the route, which you have to add as cache metadata to the block. You can then base the decision which view mode the node uses on this route by checking _entity_view of the route definition. If the view mode is controlled by code somewhere else you need to pull this in as context as well.


How to migrate text format I'm figuring out how migrating works. When trying to migrate one of my nodes from a Drupal 7 site to Drupal 8 site I can't figure out how to set the Text Format of a field. I found this solution below, when looking for an answer, but this doesn't work.

field_name:
      plugin: get
      source: field_name
      process:
        value: value
        format:
          plugin: default_value
          default_value: "basic_html"

I also tried something like

field_name:
          plugin: get
          source: field_name
field_name/format:
          plugin: default_value
          default_value: "basic_html"

Or

field_name/value:
          plugin: get
          source: field_name
field_name/format:
          plugin: default_value
          default_value: "basic_html"

But non of these work. What am I doing wrong?

Have you tried removing the quotes?

field_reference:
-
  plugin: sub_process
  source: field_reference
  process:
    value: value
    format:
      plugin: default_value
      default_value: basic_html


Drupal cannot create sites/default/files even though permissions seemed to be set to standard I continue to get an error message regarding file permissions on a sandbox server running RHEL 7

$ drush wd-show
 ID   Date          Type      Severity  Message
 398  15/Jun 20:15  file      error     The directory sites/default/files exists but is not writable and could not
                    system              be made writable.
 397  15/Jun 20:15  file      error     The file permissions could not be set on sites/default/files.
 396  15/Jun 20:14  file      error     The directory sites/default/files exists but is not writable and could not
                    system              be made writable.
 395  15/Jun 20:14  file      error     The file permissions could not be set on sites/default/files.
 394  15/Jun 20:12  file      error     The directory sites/default/files exists but is not writable and could not
                    system              be made writable.
 393  15/Jun 20:12  file      error     The file permissions could not be set on sites/default/files.
 392  15/Jun 20:12  file      error     The directory sites/default/files exists but is not writable and could not
                    system              be made writable.
 391  15/Jun 20:12  file      error     The file permissions could not be set on sites/default/files.
 390  15/Jun 20:11  file      error     The directory /var/www/drupal-private-file-system/tmp exists but is not
                    system              writable and could not be made writable.
 389  15/Jun 20:11  file      error     The file permissions could not be set on
                                        /var/www/drupal-private-file-system/tmp.

I have followed the model from Securing file permissions and ownership. Even though my file permissions are as such:

[dev@sandbox sites]$ ll
total 8
drwxr-x---. 6 dev apache   61 Jun  8 14:38 all
drwxr-x---. 4 dev apache   55 Jun 15 15:08 default
-rw-r-----. 1 dev apache 2365 May  6 23:13 example.sites.php
-rw-r-----. 1 dev apache  904 May  6 23:13 README.txt

and

[dev@sandbox default]$ ll
total 24
drwxr-x---. 3 dev apache    37 Jun 10 13:35 behat-tests
drwxrwx---. 3 dev apache    35 Jun  5 15:21 files
-rw-r-----. 1 dev apache 24103 Jun  8 10:30 settings.php

The folder structure looks like the following...

[dev@sandbox sites]$ tree -d -L 2
.
├── all
│   ├── libraries
│   ├── modules
│   ├── tests
│   └── themes
└── default
    ├── behat-tests
    └── files

My question: Where did I go wrong? Is there something you see here that I don't?

I disabled SELINUX by changing to disabled.

$ cat /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

I would love to understand SELinux better or how to tune it in regards to Drupal.


Does "composer remove drupal/module" actually uninstall the module first? Does composer remove drupal/module actually uninstall the module first,  especially in  multi-site environments?

On the other hand, does composer require "enable" the given module for all sites?

No, Composer doesn’t install or uninstall modules in the site itself.

It’s a dependency manager; all it does is compute your requirements, then download them.

You might be able to add a post install/update command to automate it, but trying to make it generic would probably be a pain.


1 Better exposed Filters for 2 views blocks I would like to make a page with 2 Views blocks. The views show the same content type, but in a different format.

Block A contains an OpenLayers map.

Block B contains a listing result.

I want to filter both Views based on taxonomy, but with one exposed filter block.

I've made one Better Exposed Filter for block A, but I don't know how to control both blocks with one exposed filter.

Can anyone help?

You want to create an attachment view display and add it to your main display. For example, if you currently have the OpenMaps display working, create a listing display as an attachment and attach it to the OpenMaps display. Make sure you set "Inherit exposed filters" to "yes" to ensure both displays are using the same set of filters.
In views 3 you can find this settings in the Attachment display settings:


How to setup Drupal Performance Monitoring to Bypass Varnish? I have lots of uptime problems with my Drupal hosting company this month.
Most of the time my Pingdom monitor doesn't even alert of the problem because Varnish is still able to serve a cached homepage.

How can I bypass Varnish to check true health of the Drupal instance? They have a username/password option but I'm sure that's for the http username/password and not for a form based login.
If I specify a fake session cookie I could bypass Varnish but then Drupal would just redirect me to the home page?

I could bypass it by adding a "NO_CACHE=1" cookie to the request. Using a POST instead of a GET request will bypass Varnish as well.


Content Types and the db tables they create I'm creating an application where I want a content type with quite a few extra fields.
When I try and retrieve this type programatically the DB is showing that each of the extra fields are stored in their own table. This is fine I guess but will mean my queries/views will be quite long and any changes to the fields via the admin console will require a bit of back end work.

Is this just a price I have to pay or is there another option?
If possible I want to be able to administer the fields as normal (changing their names say and maybe adding new ones) and not have this affect my code too much - so in essence I want my cake and eat it!

As always, thanks again...

(drupal-7.14 Lamp)

You can use views to create the queries for you so you can easily change your views in the back-office without the need of messing with custom code.
Or if you want to write the views yourself use the EntityFieldQuery class to create custom views without writing joins yourself because this is defenitivly not the way to do it.
You can load the full node object programmaticly by using node_load() and filter the fields you need. This loads the full node object so this can slow down the system when loading lots of nodes using node_load_multiple().
And finally if you think this isn't straightforward enough consider writing your own entity where you can add all fields inside your custom table(s) and get the entity data with simple queries.
When using the views module you can add your entity to the views data by using hook_views_data. There is also the possibility of adding fields to your entity so this opens a lot of opportunities if really needed. It's a bit of extra work to install, especially the first time u use entities so you have to see if the budget allows room for testing and debugging.
An introduction to entities


How can I find a module or activity that is excessively writing to the database? Problem:

We have two productions servers: primary and failover. The two machines are linked via mysql replication. The mysql relay logs are clogging and bringing servers down the failover server. I see dozens of mysqld-relay-bin.000Xxxx files in /var/lib/mysql on the failover box.

My Question:

How might I find if a module or some other activity is doing excessive database writes?

Why am I asking a sql question on DA?

Now I'm asking this in Drupal Answers because we're trying to trace this from source to destination. I have a suspicion that we have a module that is a bit over-aggressive at logging. We only have two content editors and changes are made on a few pages a day. I've also asked a similar question on https://superuser.com/questions/869776/ to see if there is a more mysql-specific remedy.

Master my.cnf

$ cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# sync
log-bin=mysql-bin
server-id=1
expire_logs_days = 1
max_binlog_size  = 100M
.
.
.
# sync config
log-bin = /var/log/mysql/mysql-bin.log
binlog_do_db=drupal
server-id=1

Replicant (Slave) my.cnf

$ cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

server-id=2
master-host=xxx.xx.xx.xxx
master-user=slave_user
master-password=XXXXXXXXXXXXXXX
master-connect-retry=60
replicate-do-db=drupal
slave-skip-errors = 1062,1054
expire_logs_days = 2
max_binlog_size  = 100M
ssl

Various or interesting finds in the logfile via tail -n 10000 messages | grep drupal | grep -v "page not found"  | grep -v "access denied"

Warning: in_array() expects parameter 2 to be array, string given in context_menu_tree_add_active_path() (line 128 of /var/www/html/sites/all/modules/context_menu_block/context_menu_block.module).

Other considerations:

Drush runs once an hour via the OS's crontab. We pull in multiple calendar and RSS feeds to keep updated content.
We've recently migrated this site to Drupal. Our log files still indicate a few broken, dead links that spiders are finding. Which if I had db_log/watchdog enabled would be an obvious culprit.

I recommend turning on mysql query log and examining types of queries flooding your server.

Or, pay for a product like New Relic or AppDynamics which provide per-url PHP performance metrics (including DB usage) of your application on web servers.


How do I add an expression into a query? When I use the code below, I get the following error:

  Call to a member function addExpression() on a non-object

 $query = db_select('node', 'n')
    ->fields('n', array('nid'))
    ->execute()
    ->fetchAssoc();
  $query->addExpression('MAX(nid)', 'max_nid');

What is wrong with that code?

Change the code to the following one.

$query = db_select('node', 'n');
$query->fields('n', array('nid'));
$query->addExpression('MAX(nid)', 'max_nid');
$query->execute()->fetchAssoc();

The value returned from fetchAssoc() is an array. Since you are assigning the value returned from fetchAssoc() to $query, and then calling $query->addExpression(), you rightly get the error. You cannot call a method on something that is not an object (in this case, an array).

If you want to list all the node IDs and set max_nid to the maximum value, you can use the following code.

$query = db_select('node', 'n');
$query->fields('n', array('nid','type'));
$query->leftJoin('node', 'n1', 'n1.type = n.type');
$query->addExpression('MAX(n1.nid)', 'max_nid');
$query->groupBy('n.nid');
$result = $query->execute()->fetchAll();4


Moving or creating many product variations Problem:
many, many product variations.  Think of it as a product configuration tool to customize your item.

I tried this:
https://www.drupal.org/project/commerce_bpc

It did create variations, however there seems to be some issue where they exist only as variations,  they don't get attached to a product (if that makes sense).  Basically, I can only see them under the admin list of variations.

Question 1: What's the most effective way to auto-generate many variations of a product?

Question 2: Can I somehow attach these variations to a product now that they're generated? Happy to do this directly in the database and/or create a standalone script to do so.

I may very well be missing something obvious, this "many variations" problem must be quite common.

Question 1:
until some awesome person posts a different answer, I'm afraid the answer to this is to use "commerce_bpc" to generate all your variations, and then attach your variations to the product by writing a standalone script.  See below.
Question 2:
you can attach variations to a product after they've been created with "commerce_bpc".
field_data_field_product is the table that links variations to products.
Adding new rows where "field_product_product_id" is the variation you want to attach to a product will attach the variation to the product.
also,  add the same row to:  field_revision_field_product and clear cache.


Custom attributes for a menu item I have to create a menu that includes items in a variety of languages including Arabic and Farsi.

Something like this:

-LTR item
-LTR item
 RTL item -
-LTR item
 RTL item -

Is there a way to add the dir='rtl' to specific menu items?

And more importantly, is there a way for me to make this accessible to non-technical users that will be maintaining the site after I have created it?

The site is being built in Drupal 8

Ideas?

Maybe starting from https://www.drupal.org/project/link_attributes and contributing a dir attribute patch (this way you have a UI for non tech users that will maintain the site)


Drupal front page and facebook crawlers I've got a drupal front_page that reditects all anonymous users from blogs to front page. But I want to facebook clawler see my og: data, to post comments with current title. Facebook crawler got 302 on front and takes title from front page.

How can I do a (maybe) whitelist to facebook crawler to take og: data from restricted area?

It depends on way how you made the redirection. Rules? Then add condition that tests user-agent and identify if it is not FB crawler. If you don't like PHP snippets you can do it by check Context which tests user-agent.


Programmatically load the uid of the owner of a viewed profile2 entity Using Display Suite together with Profile2 and Flags. I want one of my flags to be visible on the profile2 page, but only to the owner of the profile page and to the administrator.
I try adding a code field with Display Suite. I can get the field to display, I can get it to display to only administrators, but I don't find a way to allow only owner and administrator to view the flag.
What I need is the uid of the user viewing a profile (I've got that one), and then I need the uid of the owner of the profile being viewed, and compare them.
The profile2.module source has the following lines:

$account = isset($account) ? $account : $GLOBALS['user'];

    if ($account->uid != $profile->uid) {

      do something here.

    }

That looks like it is what I need, but I don't seem to be able to implement it. Any help would be appreciated.

Try with :

global $user; //is the current user

// you can get the viewing user id :
$user_id = arg(1);

if ($user->uid != $user_id){
}


Add a file-download widget on a form I have a file field called "contracts" between my user fields.
What I want is that in the user-profile form this field would come up as a file-download widget.

Does anyone have an idea how to show a file-download widget (even a link to a file would work) in the user-profile form?

Assuming that Your Drupal 7 site is a new site (not upgraded from a D6 installation), I think the best approach is to use the Profile 2 module (dependent on Entity API) and add a file field to the user profile.


How to view PDF files in a modal/overlay I have pdf (managed) files on the server that I want users to view in a modal. This will be part of a module I'm creating. There are a couple of modules that help with this, but I haven't found a good way to incorporate those yet.

One of the most promising seems PDF Reader, but it requires you to create a node before it will do its magic. I would like to just use the file (managed file, stored using Drupal) and not create a separate node for each file.

I'm open for any suggestion. I have already implemented some CTools modals and Modal Forms (for easy display of Webform content) so I can work with that. But maybe it would be easier to create a node on the fly of the content type created for PDF Reader (say pdf file) and show that with a custom node--pdf-file.tpl.php. But how to create such a node then and how to get it in a modal?

Or maybe there is a more simple solution altogether. I'm using Drupal 7.

PDF Reader does not require you to create node. It only requires you to have file in a field, in any kind of entity. If your file is managed, something uses it (in usage table). just expose that data to entity api, make file a field and you are good.

If you want to avoid entities, this module is open source. Use it as a learning tool. Borrow it's code. Give credit where credit is due, and use as you need.


how to add an event subscriber when the user reaches the login form I am new on Drupal 8 , I have implemented a hook 'hook_form_alter' in my module to add a new field to the login form , but now I want to handle it with the event , I want to trigger an event when the user reaches the login form and then add this field using event not a hook.
Can anyone please suggest me how to do it ?
This is the hook
function my_module_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if ($form_id == 'user_login_form' ) {
    // Add placeholders.
    $form['condition'] = array(
      '#type' => 'checkbox',
      '#options' => t('Enable'),
      '#title' => t('J’accepte les conditions'),
      '#required' => true,
    );
  }
}

You can't, not with core alone. D8 doesn't have a form-alter event.
D8 added events as an alternative to some D7 hooks but didn't fully replace all the hooks available. Replacing all hooks was mooted for a D10 goal but didn't make the cut.
As such, the only way to do this modify core functionality like:

Patch core (see issue comment) to add form-alter events.
Do something like Hook Event Dispatcher which wraps custom form-alter events around a hook_form_alter handler.

Then add an event subscriber for it.


Create a hook function I want to create a hook function so that other modules implement it, any pointers to how it is done?

Essentially there are 2 things needed to create your own hook(s).

  Create your own function that calls module_invoke_all('WHAT_YOU_WANT_YOUR_HOOK_TO_BE_CALLED');
  Create your new module and a function called YOURMODULE_WHAT_YOU_WANT_YOUR_HOOK_TO_BE_CALLED()

  That is ALL it actually takes to implement your own hooks in a Drupal module. The great thing here is the flexibility that it provides for you to do anything, AND allow other developers to easily extend your work. The major consideration I can see here is naming your hook. You should obviously try to choose something unique to your module, that a
  core or another contributed module wont be using.


How can I create a block that shows the total items in my cart? I'm using Ubercart ajax cart, and I want to create a static block with AJAX that only shows the total items in the cart.

How can I go about doing this? Is there a module that has this functionality?

You can test this one -

Put below code in your page (create new page content) and select input format "php" and hit preview button you will get what you want (if cart is not empty).

<?php
        $items = uc_cart_get_contents();

        foreach($items as $item){
            while(list($key,$value) = each($item)){
                if($key == 'qty')$qty = $value;
                if($key == 'price')$price = $value;
            }
            $total_qty += $qty;
            $total_price += $qty*$price;
       }
       echo 'Total Quantity : '.$total_qty.' Total Price : '.uc_currency_format($total_price);
    ?>


Given $form, how to programmatically generate its corresponding $form_state? The media_mover module contains this function, which builds a form and pre-populates default values:

/* step 1 */ $form = media_mover_api_configuration_base_form($configuration);

It also contains this function, which submits the form:

/* step 2 */ function media_mover_api_add_config_form_submit($form, &$form_state)

I would like to programmatically generate the form (step 1), and then programmatically submit the form (step 2).
Step 1 is not a problem; I am able to generate $form.  For step 2, I need $form_state.

Given $form, is there a way to programmatically generate its corresponding $form_state?  I am using Drupal 6.

This is a more detailed explanation of what I am trying to accomplish.
I am able to programmatically fill out and submit a particular form by laboriously setting all the field values in $form_state['values'], and then calling media_mover_api_add_config_form_submit($form, &$form_state);

However, the process would be  much simpler if I could instead use this function, which converts a $configuration object into $form, and does all the heavy lifting:

$form = media_mover_api_configuration_base_form($configuration);

This function enters a default value into each form field.
The only missing step, then, is to copy all these default field values from $form to $form_state['values']. I am wondering whether there is a function to do this.  Or is there a way to loop through all the fields in $form and extract the field-name and default value?

Here is what I did to fill $form_state['values'] with the default values from $form:

function mymodule_get_form_state($form){
  $values = array();
  _mymodule_form_get_values($form, &$values);
  $form_state = array();
  $form_state['values'] = $values;
  return ($form_state);
}

function _mymodule_form_get_values($element, &$values) {
  foreach (element_children($element) as $key) {
    if (isset($element[$key]) && $element[$key]) {
      if (isset($element[$key]['#default_value']) && $element[$key]['#default_value']) {
        $values[$key] = $element[$key]['#default_value'];
      } else {
        // Recurse through all children elements.
        _mymodule_form_get_values($element[$key], &$values);
      }
    }
  }
}


i18n module is acting up weird I have a site with two languages (Dutch and English).
However if I want to translate a Dutch node I must use the Dutch admin interface, and if I want to edit an English node I must use the English admin interface.

So let's say node/1 is in Dutch and node/2 is English, and my default language is Dutch.
Now, if I go to /node/2/edit, so the edit form of the Enlish node in the Dutch language it redirects to /node/1/edit
If I really must edit the English node I must go to /en/node/2/edit

Also the translated nodes are not present:

While I think it should also display which node ID's are the English and Dutch language on here. Like below:

The part in red is here like it should, but not on my production site as you can see in the first picture.

The second thing is that normally you can edit Dutch, Spanish, and English from the English admin pages. On my production site this I cannot do this. There I have to switch to the Spanish admin interface to translate to translate in Spanish, and I need to switch to English to translate to English.

What am I missing here.

A possible explanation for your problem might be because of your "language detection" configuration.

Check this configuration via Configuration -> Languages -> detection and selection: the order should be 'URL, Default, User', and not something like 'Default, URL, User'.


Theme generic file link in node template I want to change the text on a link to download a file in my node template. In Manage Display I have selected  Generic File as the formatter which outputs this

but I want to change it to this

How can I do this?

You can function theme_file_link() , you can change the file link title before html rendered for file link in your custom themes templete.php file.


create node with a field and it updates another field in a view, elsewhere on the site (using D7) I'd like a user to be able to create and save a node of a certain content type and have it so the value or setting of one of the fields called "location" will then update the same field (or another field that tells the user the "location") that's part of a view elsewhere in the site? I'll also want to plot the "locations" of things on a map using openlayers later on.
I've looked at rules so far and haven't seen how to do it with rules, but I'm new to rules. And I've seen entity reference, which looks like it takes the place of D6's node reference, but I'm not sure how to use it in this way. So how can I do this?

Sounds like you could create a rule where:

Event = Node->After saving new content

Condition = Node->Content is of type (your "certain content type")

Action = Set a data value.
Use the data selector to drill down to the field that your View elsewhere is displaying for location. Hit Continue. Use the data selector to drill down to the field in the recently created content that your user has entered the location data into. Save.


extend $.fn or Drupal.ajax.prototype.commands for calling javascript after ajax callbacks Use case: You call ajax, and want to call some custom javascript (js) with some parameters as part of the response.

Issue: Two different solutions exist.

Questions:

is there a preferred method or is this just a matter of style?
are there differences in the benefits of each approach?

(there are a few questions eg 1 which supply different methods)

(Sorry these two examples may not be perfect - so feel free to edit)

Extend JQuery: $.fn

php:

$commands[] = ajax_command_invoke(
  NULL,
  'mymodule_command',
  array($data)
);

js:

$.fn.mymodule_command = function(data) {
  // dialog ajax id
  var dialogAjaxId = data.id;
  var blah = JSON.stringify(data.values);

};

Extend Drupal: Drupal.ajax.prototype

see this example

php:

$commands[] = array(
  'command' => 'mymodule_command',
  'arguments' => array(...),
);

js:

Drupal.ajax.prototype.commands.mymodule_command = function(ajax, response, status) {
  console.log('mymodule_command', ajax, response, status);
  console.log('arguments', response.arguments);
};

Extending Drupal.ajax.prototype is the way Drupal and almost every contrib handles this.

is there a preferred method or is this just a matter of style?
are there differences in the benefits of each approach?

The preferred method would be the latter. However, note that both methods are not the same. Ajax commands are passed through ajax_render() function, which allows modules to alter the ajax commands by implementing hook_ajax_render_alter(&$commands). If you use the former method, you will see the invoke as the command, which makes it difficult to figure out the exact invoke command.
For Javascript eyes, it's just a matter of $.fn (shorthand for jQuery.prototype) vs Drupal.ajax.prototype.


Hooking into updates to an entity reference field within Parent node Let's say I have a Structure Content type called "Fruit", and it only has a title.

And I have another Structure Content type called "Color" which is a dropdown menu with a few colors in it.

And i have an "entity reference" for Color on Fruit. So when I go to add a new Fruit, I can input in the Fruit title field "Apple", and then choose from the Color dropdown menu "Red".

I have a hook for node_update() which triggers when I change the Title of the Fruit. But when I change the Color, this trigger is not executed.

Which hook should I use if I want to track the Color changing on a Fruit?

This is for Drupal 7. Thanks so much in advance for your time and insight.

You don't have a direct connection for those(the same way some entities work at least) so best approach would be to have a node_update for Color and then inside it to query (can use entityQuery) and see which fruits have that color, from here you can do your stuff.

the following pulled out of my head since I haven't touch D7 for over a year so here we go

function node_update($node){
  if($node['type'] == 'color'){
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'fruit')
    //value or target_id
    ->fieldCondition('field_photo', 'value', $node['nid']);

    $result = $query->execute();
  }
}


Mapping a UID on custom module content Dear Drupal Enthusiasts,

I was hoping that one of you may be able to solve a problem I'm having with the Feeds module and its unique identifiers.

Basically, I would like to be able to target a field with a unique identifier like you can do with any ordinarily created content-type. However, I want to do this on a custom module (which has its own form of unique identification).

In other words, I have a field in my custom module that is unique, but Drupal does not know that this field is unique. How do I both tell Drupal that this custom module contains a unique field and identify that field as unique so that I can update content rather than delete it and replace it every time I wish to import data?

Any guidance would be most helpful!

Thanks!

So I was able to resolve this problem with a simple fix - though it took a good deal of time to find it, so I figured I'd post it here to inform others in the event they have a similar difficulty.

I simply used the Field validation module which gives the user the capability of selecting his/her own UID for any field instance...quite straightforward.

Hope that helps!


Why are all files (except index.php) being redirected to 'index.html'? We have a Drupal 7 Drupal Commerce site that we've just moved to our virtual private apache server, however we're seeing very strange behaviour that's making the site not work.

We're getting a strange problem where many files (images, CSS, JS) are getting "307: Temporary redirect"s to 'index.html', which doesn't even exist.

We have a very ordinary apache setup (no unusual settings), and the htaccess file of our website is straight from Drupal core - we haven't edited ourselves.

Is this a problem with the way we've set up Drupal, apache, DNS, or something else?

There is a Rewrite Rule written in .htaccess as,

# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

This may be your problem.

There are few assumptions that can be the reason why its happening :

Please check the method you the using to access files.
It might be your server issue which does not provide correct access rights for accessing the files
Your files are not properly placed in correct locations.


How to add a pane (view content pane) to an existing panel page via a Feature module or programmatically? I have feature module A that provides content type X and a panel variant for content type X.

I have another feature module B that provides content type Y and a view content pane of three latest items of type Y.

From feature module B, how can I add a panel pane of the view content pane Y to the panel variant for type X in Feature A?

Is this possible?

Let me know if that's too abstract or ambiguous, and I'll clarify.

This looks like the start of what can lead into you what I call "Features Hell". :)

It's possible to make features more maintainable and minimize conflicts if you organize them by small groups or single feature components. Here's what I mean:

You have content types X and Y
You have, I assume, panelizers for content type X and Y
You have views with content pane displays that you want to add to a
panelizer

This can be done by divided up your features into four different modules.

foobar_field_bases: contains the fields from content type X and Y under the "Field Bases" component. This stores the global settings of the fields.

foobar_content_types: contains content types X and Y from the features Content Types component, and the content type fields under the Field Instances component.

foobar_views: contains all your views

foobar_panels: contains all panel-related components such as panel layouts, panel renderers, panelizers, page managers.

It may seem like that's harder to maintain because you have more modules now, but consider your issue. You want to update the panelizer content with a view content pane. All you do is make sure the view is in foobar_views. If not, recreate foobar_views with your new view. If it is, update the foobar_views feature so it contains the new display in the feature module. Then do a feature update on foobar_panels.


REST export with no data over it's localhost IP I have a REST export which provides data with a call (curl or browser) to the Drupal URL(s). But we need to get these data over a curl to vhosts IP-Address and from this address, which is 192.168.34.11.

curl http://drupal.url/view.json from every other device and curl http://192.168.34.11/view.json from others in the same NAT works.

curl http://192.168.34.11/view.json local from 192.168.34.11 does not work. In this case I only get []

There are no access or permission restrictions set in the view.
We use the https://www.drupal.org/project/domain module and I have configured a domain 192.168.34.11.

Why isn't the view accessible over it's localhost IP address?

OK, solved. The problem was the domain access module.

I got no output because I didn't set the domain access for all nodes except one. The one I got in ouput.

There is no default value for the domain access field in field configuration in node type configuration. And it's not comfortable to set the domain access values for every single node in node edit. So I needed to disable this module.


Is there a way to delete unused fields? I created many fields for content type.Now I don't need these fields anymore.
I deleted the fields from the content type but the fiels data remains in the database.

How can I delete the field and all its related data?

Sometimes running cron does not entirely delete a field, especially if the field was ever used in a field collection. First, make sure the field isn't used anywhere else. Check all content types, field collections, custom user fields, etc. if the field is really not used but running cron does not delete the field table from the database, you may have to delete it manually. You can do this manually with a SQL query or via phpmyadmin.


How do I add a #process callback to a fieldset form element without overwriting the existing callbacks? I am using the following code.

$form['my_fieldset'] = array(
  '#type' => 'fieldset',
  '#title' => t('My Title'),
  '#collapsible' => TRUE,
  '#collapsed' => TRUE,
  '#access' => TRUE,
  '#process' => array('my_callback_function'),
);

If a fieldset is collapsible, it gets two callbacks at some point later.

form_process_fieldset | (Callback) form_process_fieldset();
ajax_process_form | (Callback) ajax_process_form();

They aren't added to the array with my callback function. If I look at the form array, there is only my callback; so, there is no collapse functionality.

I tried to avoid that by adding the callback in hook_form_alter(), but this is too early; the callback functions are still not there.

$form['my_fieldset']['#process'][] = 'my_callback_function'; //Not working eather

So where is the right place to add a #process callback to my own form element, so it gets added as last callback in the callback array, or at least is not destroying the callbacks implemented by this specific form element itself?

I do some calculations in the callback to set #access = FALSE for this fieldset under certain conditions. This works fine, but maybe this is the wrong way to do it.

The documentation on #process says:

  You will probably want to add to the existing array rather than writing over it, so don't follow this usage example exactly.

The documentation is not very helpful, I don't follow but there is no info how it is done right.

When you add a #process function to a form element, the default ones defined from hook_element_info() are not added. Using hook_form_alter() to add a #process function doesn't change the result, as hook_form_alter() is invoked before the default #process functions are added to the form element. This happens in form_builder(), which uses the following code.

 // Use element defaults.
  if (isset($element['#type']) && empty($element['#defaults_loaded']) && ($info = element_info($element['#type']))) {
    // Overlay $info onto $element, retaining preexisting keys in $element.
    $element += $info;
    $element['#defaults_loaded'] = TRUE;
  }

If $element['#process'] is already set, it doesn't get overriden by $info['#process'], which means the default functions are not added.

What you can do is invoke the default #process function from the one you define. If mymodule_process_function() is the function you add, it should contain code similar to the following one.

function mymodule_process_function($element, &$form_state) {
  if (isset($element['#type']) && ($info = element_info($element['#type'])) && isset($info['#process'])) {
    foreach ($info['#process'] as $process) {
      $process($element, $form_state);
    }
  }
  // ...
  return $element;
}

If the #process function is necessary in any form where a fieldset is present, then you can implement hook_element_info_alter() to alter the information returned from system_element_info() about the fieldset form element.

  $types['fieldset'] = array(
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#value' => NULL,
    '#process' => array('form_process_fieldset', 'ajax_process_form'),
    '#pre_render' => array('form_pre_render_fieldset'),
    '#theme_wrappers' => array('fieldset'),
  );

The alternative that requires less code to be written is to add a #after_build function to the fieldset. #after_build functions are functions that are called after the #process ones, receive $element, and &$form_state as argument, and need to return $element. As system_element_info() doesn't set any #after_build function, there is less code to execute.
For compatibility with any module that implement hook_element_info_alter(), and which could alter the fieldset definition, code similar to the one I shown before should be used also for the #after_build property.


Template suggestion does not work for table in a custom block / Might there be a way around? I created a block on pages of the "Author" content type that lists all the articles the author has contributed to in a table (via contextual filter). Now I want to customize the table layout. I already did this before in a similar case, where I show the table on a page, not in a block. There I get file name suggestions for the template inside HTML comments like that:
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'views_view_table__articles' -->
<!-- FILE NAME SUGGESTIONS:
   x views-view-table--articles.html.twig
   x views-view-table--articles.html.twig
   * views-view-table.html.twig
-->
<!-- BEGIN OUTPUT from 'themes/MYTHEMEFOLDER/templates/views/views-view-table--articles.html.twig' -->

But in my latest case, the table in a block, I only get this suggestion:
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'views_view_table' -->
<!-- BEGIN OUTPUT from 'themes/MYPARENTTHEMEFOLDER/templates/views/views-view-table.html.twig' -->

Note that it outputs the template of my parent theme, not my actual theme.
I did some research and found this issue, which currently is not resolved and the proposed patch not included inside the Drupal code. Is this the reason I cannot create a custom template or is there something else I can do?
If not, how would I create that table of referenced articles on the author's page?

Since Drupal doesn't suggest certain template file names I had to create a custom module which adds the template name for my needs. I had to implement the hook_theme_suggestions_HOOK() for my table view and add an appropriate name to the suggestions array.
<?php

use Drupal\views\ViewExecutable;

/**
 * Implements hook_theme_suggestions_HOOK().
 */
function custom_template_suggestions_theme_suggestions_views_view_table_alter(array &$suggestions, array $variables) {
  if (isset($variables['view']) && $variables['view'] instanceof ViewExecutable) {
    $id = $variables['view']->current_display;

    if (!in_array('views_view_table__' . $id, $suggestions)) {
      $suggestions[] = 'views_view_table__' . $id;
    }
  }
}


Taxonomy Term Hierarchy(not programmatically nor content related) I know there are zillion topics about this, but I just couldn't apply it to my View Block in Drupal 8. On the other hand all these Taxonomy Term Tree creation is based on content related.

Here is what I would like to do, I would like to display my "Collections" taxonomy term hierarchy without content relationship, as it is(just parent-child terms). This is how my taxonomy term hierarchy looks like:

And this is how far I could get:

This is my result(which is completely wrong):

**FYI: I am using Views Tree and I follow this Taxonomy display children with Taxonomy View Depth not working **

Thank you for help and time in advanced.

you can use the Views Tree module for this: https://www.drupal.org/project/views_tree

It works pretty well, you just need to use the Tree (list) views FORMAT, add the parent taxonomy term in RELATIONSHIPS, add the parent term's Name field to the FIELDS list, and then use it as the Parent field on the Tree settings:

The module will link the terms hierarchically and output a nested list, and you can always hide the parent term's name field to show just the children terms names.


Theming site name in mayo over Flexslider slideshow header? I asked this originally in the Mayo support on drupal.org but got directed here.

Continuing my development of my main work website has continued to use Mayo as I find it brilliant and simple.

This week I've managed to implement the Flexslider module using views slideshow and views to construct a new header.

The issue I have which i could do with some support with and that is theming the sitename and slogan to overlay on the left to match the title on the right. Ultimately I will link the title on the left to content of that service but first i need to get this sitename issue sorted.

No matter what i do, i cannot get the sitename to display in front of the flexslider?

I have managed to theme the title of the image within the view fine so i dont think its a flexslider issue but wondered if there is any thing i need to over ride with additional css within the mayo theme itself using css?

I currently have the sitename off until i sort this issue out but see the attached picture which shows the inspected code and where the div is currently via chrome inspect tool.

Ok I've sorted it.

Use the Module: Views variable field

Add the field to the View for the slideslow / flexslider.

Add the site_name variable to the field.

Rewrite as Link and type in

Rearrange the fields so that it is Site name then Slideshow then Caption

Save.

Rewrite the CSS to grab the site name div and place it where you want.

Remove some annoying div whitespace

Be happy!


How and when are commerce licenses created, and when does the state change to "active"? I'm working on a module that attempts to tie commerce_license in with the ACL (Access Control Lists) module.

I am attempting to sell access to an individual node. I have a product type, product, and product display which does this. I have a node reference field which allows an admin to select which node to license on product creation, and this reference field is being correctly referenced in my license class (the one in plugins/license_type/ which extends CommerceLicenseBase).

In my save() function, I'm checking to see if the status is COMMERCE_LICENSE_ACTIVE before I add the license owner to the acl, but it appears that the license never gets in this state. I have gone through the checkout process, and even manually completed the order, but I don't ever see the license get to the "active" state.

I've also noticed that the license seems to be created (the save() function is called) when a product that is associated with a license is added to the cart, and NOT on checkout, as is stated in the documentation.

I think the real issue is in my lack of understanding of how the commerce license module works (and possibly how the ACL module works, but that's a different discussion). I've read through the documentation, watched a few tutorials, and looked through the example code, the commerce_license_role module, as well as the commerce_license_og and commerce_file modules, and I'm still not sure what I'm doing wrong - I'm beginning to suspect that my error is not in the code itself, but rather in configuration.

Here is my code:

<?php

  public function save() {

    if ($this->uid && $this->product_id) {

      // Get the entity referenced
      // (this works fine - field is defined in the .module file)
      $node = $this->wrapper->product->commerce_license_acl_node->value();
      $acl_name = 'ACL_' . $this->product_id . '_' . $node->nid;

      // Get the acl associated with this node and product ID
      $acl_id = acl_get_id_by_name('commerce_license_acl', $acl_name);

      // If the ACL doesn't already exist, create it
      if(empty($acl_id)){

        // Create ACL if one is not already associated with this license
        $acl_id = acl_create_acl('commerce_license_acl', $acl_name);

        // Grant ACL users read access to this node
        $read   = TRUE;
        $update = FALSE;
        $delete = FALSE;
        acl_node_add_acl($nid, $acl_id, $read, $update, $delete, 0);

      }

      $owner = $this->wrapper->owner->value();

      // I realize a lot of this is redundant. I'm covering all the cases here for my benefit
      // in trying to understand what is going on.
      switch($this->status){
        case COMMERCE_LICENSE_ACTIVE:
          // *** This case is never true
          acl_add_user($acl_id, $owner->uid);
          drupal_set_message('license_acl set to active');
          break;
        case COMMERCE_LICENSE_CREATED:
          // **** This is the state that it always seems to be in
          drupal_set_message('license_acl created');
          break;
        case COMMERCE_LICENSE_PENDING:
           drupal_set_message('license_acl set to pending');
         break;
        case COMMERCE_LICENSE_EXPIRED:
          acl_remove_user($acl_id, $owner->uid);
          drupal_set_message('license_acl set to expired');
          break;
        case COMMERCE_LICENSE_SUSPENDED:
          acl_remove_user($acl_id, $owner->uid);
          drupal_set_message('license_acl set to suspended');
          break;
        case COMMERCE_LICENSE_REVOKED:
          acl_remove_user($acl_id, $owner->uid);
          drupal_set_message('license_acl set to revoked');
          break;

    }

    parent::save();

  }
  ?>

Is there any documentation out there which goes into depth explaining the workflow of commerce license creation and statuses? Thanks in advance.

It looks the license is being activated when the "order paid in full" trigger fires, and I didn't have a payment system in place. I thought I had it configured to bypass this, but enabling the example payment system and the payment ui solved the problem.

However, the user still doesn't have access to the node associated with the ACL, so I need to figure that one out, as well.


How do I get translated label for a base field definition? As mentioned here and here, there is a (complicated) way, to get can get a translated labels for bundle fields.

use Drupal\field\Entity\FieldConfig;

// Override language before loading field configuration.
$language = \Drupal::languageManager()->getLanguage('fr');
\Drupal::languageManager()->setConfigOverrideLanguage($language);

// $entity_type, $bundle, $field.
$field_info = FieldConfig::loadByName('entity_type', 'bundle', 'myField');

$label = $field_info->getLabel();

I however cannot find a way, how to achieve this for base fields. A hack like supplying a(any) bundle also leads to no success.

There are two possible translation methods for a base field, interface translation and configuration translation.

Base fields are defined in code and translated by t(), which gets the translatable string from the core interface translation table.

$translatableMarkup = t($label, [], ["langcode" => $langcode]);
//optionally, render to string
$translatedLabel = $translatableMarkup->render();

If a base field override exists in configuration, then it contains a translatable label:

// Override language before loading field configuration.
$language = \Drupal::languageManager()->getLanguage('fr');
\Drupal::languageManager()->setConfigOverrideLanguage($language);

$field_override = BaseFieldOverride::loadByName('entity_type', 'bundle', 'myField');
if ($field_override) {
  $label = $field_override->getLabel();
}


Drupal Module for arranging Nodes of special type into a table||chart I'm trying to map Nodes of special Types on the basis of their field datas in a table or a chart.

The table should look like this:Table Example

Explanation: Table Header and first row are the datas of two specified fields. The node titles (rest of table) are mapped on the free table rows/columns according to their field values. Since i got no solution for this i tried to look for an approach with graphs. But it doesn't turn out as an easier way.

Maybe i've overlooked something. I would be really glad if anybody have a solution for this problem.

I'm really glad that I found a good and comfortable solution for my problem.

There are two modules available: Views Table Group, Views Merge Rows

At the beginning, I had some problems with the settings. After a few tryings I got along with these:  check "Use values of this field as a filter" instead of "Use the first value of this field"

Note: I've just seen the merged rows logged out! So you had to change the visibility/accessibility settings or just log out to check the table.

My result:


How to fix google page speed insights issue? I'm facing issues on my every drupal site when i test my website in Google page speed insight . I have configured Advagg module and followed but not succeed.Issues are below:

Eliminate render-blocking JavaScript and CSS in above-the-fold content.
Leverage browser caching.
Enable compression.

Sometimes (1) can be fixed by advagg setting but (2) and (3) need configuration in .htaccess. Can anybody provide me solution?

With AdvAgg enabled go to the status report page admin/reports/status. It should offer advice on how to fix gzip and browser caching for css/js aggregates. Also see the readme, under troubleshooting there are some tips for getting apache to do what you need it to.

If advagg doesn't report any issues then check and see what kinds of resources google is complaining about in terms of browser caching (.jpg) and compression (fonts). Also remember that if these are coming from an external domain (google analytics) there isn't a lot you can do as you don't control that server.

Edit: Guide here - https://groups.drupal.org/node/517292. It's the AdvAgg Readme file as well.


How to migrate Drupal nodes from one installation to another, preserving revision history? Is there a good way to export a set of nodes from one Drupal installation, including node revision history, and then to merge these into another Drupal installation, including revision history?

I'm familiar with modules such as Node Export and Backup and Migrate...  But Node Export doesn't preserve revision history, and Backup and Migrate doesn't allow merging (only full table replacement).

You can also try UUID and UUID Features, can export both Nodes and Nodes revisions.


How to import the node class into a title field of a view? I installed the Node Class module. I have a view, where the node class should be imported into the title field of the view.

How can I achieve this?

As far as I understand, you want to add a class name to the title field of your nodes listed in a view. (1) Views provide this functionality by default:

Adds the class to the selected html element, <span> is by default.
It can be used as a field wrapper.

(2) In case this is not suitable for you, you may very well use view's "rewrite results" :

It can be used to wrap the field's text.

(3) Lastly there is always the preprocess_views_view_fields solution where you can edit your field's attributes:

if($view->name == 'view-name') {
  $vars['fields']['title']->wrapper_prefix = '<div class="views-field views-field-title my-class">';
}

It can be used as a field wrapper.


Drupal 7 Form API not returning all values into $form_state I have a form with multiple similar fields like so:

<?php

example_form($form, &$form_state) {

   for($i = 0; $i < 10; $i++){
       $form[$i]['name'] = array(
           '#title' => t('Name'),
           '#type'  => 'textfield',
       );
   }

   $form['submit_button'] = array(
       '#type' => 'submit',
       '#value' => t('Submit Names'),
   );

   return $form;
}

This outputs ten fields and a submit button. However, inside hook_form_submit and viewing the values from dpm($form_state['values']), there is only one instance of name.

I can easily fix this problem by uniquely naming the field $form[$i]["name-{$i}"] but this solution does not seem pragmatic. What is the work around for not individually naming each field uniquely? Why is the not naming the container qualify as unique?

Submitted values are flattened by default. To change that, set the #tree property on the container (in this case the form):

$form['#tree'] = TRUE;


Call preprocess_node (or get variables) from Twig template? I have the following content types (for a simple LMS) defined:

Lessons, for which there are rather complex rules for handling view access.
Courses, which contain entity references to one or more Lessons.

Now, in the Twig template for rendering a Course node, I am trying to create a "table of contents" (a list of Lessons), using the following snippet:

  {% for key, lesson in content.field_lessons %}
    {% if lesson['#node'].title.value|render|striptags|trim %}

        <a class="list-group-item list-group-item-action
           href="{{ url('<current>') }}/?lesson={{ lesson['#node'].nid.value }}">
          {{ lesson['#node'].title.value }}
          {{ (*****) ? 'LOCKED' }}

    {% endif %}
  {% endfor %}

This works well. However, the problem with this code is the line that I marked with (*****): I would like to do a simple access check, i.e. I would like to check, if the user is allowed to view the Lesson. If not, the label "LOCKED" should be added.

In my implementation of function THEME_preprocess_node I have already defined such a check that is called whenever a Lesson is rendered:

function THEME_preprocess_node(&$variables) {
  ...
  $node = $variables['elements']['#node'];
  $variables['viewaccess'] = $node->access('view');
  ...
}

But can I call the preprocessing function for a Lesson from within the Course template to receive the variable viewaccess?

Another idea would be to modify the above snippet as follows:

  {% for key, lesson in content.field_lessons %}
    {% if lesson['#node'].title.value|render|striptags|trim %}

        {{ bamboo_render_entity('node', lesson['#node'].nid.value, 'toc_entry') }}

    {% endif %}
  {% endfor %}

so, I am now rendering the Lesson using Bamboo Twig and the output ... is fully handled by the Lesson template, which works fine. The problem now is that a Lesson that the user does not have view access for, is not rendered at all.

Now, I'm stuck. Can anybody offer any ideas?

Any help would be much appreciated.

You're pretty close. I think there are a couple of approaches to this. This is what I would do

preprocess the lessons entity reference field for the courses bundle, iterate through the values, check the access, set a variable with the access value for each item. Then in field--field-lessons.twig.html, render the field if the access value is true.

<?php
//the name of your lessons entity reference field on courses
function THEME_preprocess_field__field_lessons(&$variables) {

  if($variables['element']['#bundle'] == 'courses') {
    $account = \Drupal::currentUser();
    $ent_refs = $variables['element']['#items']->referencedEntities();

    foreach ($ent_refs as $key => $ent_ref) {
      $check = $ent_ref->access('view', $account);
      $variables['items'][$key]['my_access'] = FALSE;

      if ($check) {
        $variables['items'][$key]['my_access'] = TRUE;
      }
    }

  }
}

then in field--field-lessons.twig.html

...
{% for item in items %}
    {% if item.my_access == TRUE %}
      I'm Unlocked: {{ item.content }}
    {% else %}
      I'm locked :(
    {% endif %}
  {% endfor %}
...


Add and customize login block on page.tpl I'm trying to add the user login block in my page.tpl file. I've tried inserting the following code but  the only thing I see is the username, password and submit fields. The "Register" and "Forgot your Password" fields are not there. And I would like to do this in code form. Cause I wanna put the user login block in a specific place.

if(!user_is_logged_in() ){
    $userLoginForm = drupal_get_form('user_login');
    print drupal_render($userLoginForm);
}

Thanks :)

you can do it like this:

$block = block_load('user', 'login');
$block = _block_render_blocks(array($block));
$block_build = _block_get_renderable_array($block);

print drupal_render($block_build);

this will generate a block with title and contexual links also..


Views Data Export field format? I have created data export view. I need to include a date field in this format: Y-m-d (yyyy-mm-dd). I went to 'Date and Time', then added a new format and assigned it to the short format.

In views, I then select the date field, and select 'short' as the format. The new format (Y-m-d) displays in the view preview correctly.

I download the XLS and open it up, but the date field is defaulting to m/d/y (1/10/13). Why would the date appear correctly in the views preview but not in the download? I also verified all the correct formatters are set in the CCK date field settings. If I just show the fields in a plain old table view layout, it is also displayed correctly. the only incorrect format is in the XLS I download.

Please note: If I change the date field to include a 'From date' & 'To Date' and display both To and From dates in one column, the XLS then displays the dates correctly but unfortunately, I can't have these sets of dates in one column. I need them in 2 columns and in the 'Y-m-d' format.

To further troubleshoot, I also tried selecting the same date field in views and only displaying one date per column. One column to display From and the same date field to display To. This also results in m/d/y (1/10/13).

Is this a bug? I can replicate this on my local environment as well. Basically, the custom date formatters are not being portrayed on the export.

I am using:

Linux CentOS
PHP 5.3.3
MySQL 5.1.61
Drupal 6
Views 6.x-2.16
Views Export 6.x-2.0-beta6

The date format was being set via the Operating System. OS X's default language and text preferences was re-formatting all dates I type.

With OS X 10.8.3 the preferences are on "System Preferences >> Language and Text >> Region >> Dates >> Customize." There, you can enter your preferred date format.


Fixing configuration inspector missing schema errors I'm using the configuration inspector to fix schema issues before I put a module live as a full release.

I'm finding the following error, but I'm unclear on how to fix it.

The module provides a new entity type, private_message. In config/install, I have the file:

core.entity_form_display.private_message.private_message.default.yml

This file has the following contents (trimmed):

content:
  message:
    type: string_textarea
    label: hidden
    settings:
      placeholder: Message
      rows: 5
    region: content
    third_party_settings: {  }
    weight: null

The configuration inspector for core.entity_form_display.private_message.private_message.default is telling me that the schema for content.message.label has a missing schema:

  content.message.label     Undefined   undefined   hidden  missing schema

In the raw data for the inspection, I see:

'core.entity_form_display.private_message.private_message.default:content.message.label' => 'missing schema',

Does anyone know how I can fix this error?

Yes, remove that line. Form displays have no label control, only view displays do. Maybe this was copy & pasted somehow by hand when creating that config.


How to translate content of the composite element settings? I have created a composite element where I added a custom textarea field in the element settings.
I have added that element in a webform, filled that textarea and saved the webform.
Now I want to translate the webform, But when I go the webform translations, I am unable to translate the value of that text area.
Is there any way to translate the value of that text area?
/**
 * Provides a booking element.
 *
 * @WebformElement(
 *   id = "my_element",
 *   label = @Translation("My element"),
 *   category = @Translation("Composite elements"),
 *   multiline = TRUE,
 *   composite = TRUE,
 *   states_wrapper = TRUE,
 * )
 */
class Myelement extends WebformCompositeBase {
  public function form(array $form, FormStateInterface $form_state): array {
    $form = parent::form($form, $form_state);

    $form['element']['booking_email'] = [
      '#type' => 'textarea',
      '#title' => $this->t('some content'),
      '#weight' => '0',
    ];

    return $form;
  }
}

Here is the backend of the element settings.

And here is the webform translation interface. I can't see my textarea field so that I can translate its content. I only see the composite element key and title.

You need to create a schema config file to make them translatable.
I have done it like this by creating my_module.plugin.handler.schema.yml file in my my_module/config/schema directory.
webform.handler.my_element:
  type: mapping
  label: Booking email
  mapping:
    booking_email:
      label: 'Something'
      type: text


Block feed importer to create a new term in taxonomy I am using feed importer to bulk import the nodes in a drupal site. I have created a custom content type named Product. This content type has CCK fields which are linked with a taxonomy.

I am using CSV files to import the data. If I put a different(invalid) value in one of the field and that is not present in the vocabulary(term in the taxonomy), it creates a new term.

I want to block the creation of the new taxonomy term as it might create some invalid term in my site.

I achieved it using Feeds Tamper. We can control the fields that we want to import.


Create user after node created and assign node entity reference to it I have a content type with name hotel it have entity reference field that referenced to users entity, I want when admin create a node automatically created a user according to hotel email field and then set  user entity reference field with that new created user.How can I do it automatically?

I create a rule with below structure but not work

{ "rules_create_user_based_on_hotel" : {
    "LABEL" : "create user based on hotel",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert--hotel" : { "bundle" : "hotel" } },
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "user",
            "param_name" : "[node:field_hotel_users]",
            "param_mail" : "[node:field_mail_hotel]"
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : { "data" : [ "node:field-user-ref" ], "value" : [ "entity-created" ] } }
    ]
  }
}

Download the Rules module
Enable Rules and Rules UI

Add a new rule

React on event: After Saving New Content (it's listed under NODE)
Restrict by type: Hotel

Under Action

Add Action of Create New Entity >> ENTITY TYPE: USER >> For your EMAIL field, Ex: If you called your field "Email" then it's node:field-email. For user name, I guess you will also need to create a field in the node for that too. Then do same steps as e-mail

Note: You can always click on "DATA SELECTORS" to see all the tokens you can use.

Add Action of Set data value >> select your entity ref field (Ex: If you called your field "Test" then it's node:field-test) >> for Value use entity-created:uid
Add action of Send Account Email (listed under USER) >> Account: entity-created

  You can modify the e-mail templates here
  /admin/config/people/accounts use tokens for your needs.

  Let me know how this goes, no time to test this Rule.


How to map url_alias table to node table? I was trying to use some SQL to map the url_alias field to my node field on the url_alias.pid = node.nid field. However, it turns out that these are not apparently related, sometimes they are the same value and sometimes they aren't. As I'm looking through my mysql db I can see no connection between the url_alias table and the node table.

The url alias is coming from the pathauto module. I just want to create links to my resources when the titles occur in a sql query in a custom module...this seemed the easiest way to do it.

Does anyone have any idea on which fields or tables the connections occur between these two entities?

They are not related because url_alias table contains all the URL aliases. You can use MySQL CONCAT to concatenate strings (fields or string literals).

$results = db_query("
  SELECT
    n.nid, n.title,
    a.source, a.alias
  FROM {node} n
  LEFT JOIN {url_alias} a
    ON CONCAT('node/', nid) = source
  ")->fetchAll();
foreach ($results as $result) {
  dpm($result);
}


Minutes of meeting module for drupal 7 I have a new requirement. I need a minutes of meeting module. I.e. after each meeting i.e. weekly they will add action items and assign it to some user and as soon as the user logs in, it should be shown to him. So is there any existing module which is even close to this. I don't mind sitting and customizing the module.

I'd use a custom Action Items content type and then Rules to handle the scheduling and assignments.  Rules and fields (via content types) should be flexible enough to handle such a workflow and they have the further advantage of being well-supported and documented.


Why aren't CSS files served? There is nothing in sites/default/files/css In my Drupal 8 installation profile, I install a theme and a lot of configuration for it.  I'm using Features to install blocks/settings/views for it, but when I enable the feature Drupal stops serving ANY CSS files on page loads.

I don't think it's an issue with features, because if I wait long enough, those files will be generated by Drupal and CSS files will load as normal, it's just that Drupal assumes those files already exist.

I have tried:
- drush cr
- clearing the cache manually in the UI
- all of the individual drush cc options
- deleting the contents of all cache_* tables and clearing the cache or drush cr
- turning aggregated css off, clearing caches, turning it back on, clearing caches
- running cron
- running /update.php

...Is there any way I can tell Drupal to generate these files instead of waiting hours for it?

A few more things to check when you have issues like this:

Any noteworthy issues on the Status page? (admin/reports/status)
Does saving the File system page generate any errors? (admin/config/media/file-system)
This sometimes indicates permission or ownership issues in the file structure, which could keep the aggregate CSS and JS files from being generated?
Have you checked the error log for any noteworthy messages? (admin/reports/dblog)

Clearing the cache is a good place to start, but I see that you already did that. Try checking the error log immediately after clearing the cache to see if anything pops up.


Filter "exposed filter" data based on another "exposed filter" I have to exposed filters from 2 vocabularies, filtering results for a page. I'm using views module for this
Is there a way to create a bridge between them ? For example when I select something from the first filter the data from the 2'nd filter will change based on what I selected on first filter, and backwards.

If i'm thinking well there is no way to create a direct connection between those 2 filters (vocabularies), we have to use what they have in common, the content. So i'm guessing I need to get vocaluray 1 terms from the content after filter 2 has selected something.

Filter 2 -> generate content -> generate filter 1 data again

Is there a way to do this without "hardcoding" ? Thanks

Try the Hierarchical Select module for that

  This module defines the "hierarchical_select" form element, which is a greatly enhanced way for letting the user select items in a hierarchy.


Pass User object to Token::replace I've the following code (sample) that runs on Cron and sends SMS to users.
$token = \Drupal::token();
$message = Hey, [current-user:account-name];
$message_value = $token->replace($message);

When cron run, Getting the SMS text as 'Hey Anonymous' This works correctly on site when user logins in. but not on cron.
So I tried to pass the user object to replace the token like follows but that doesn't work. Getting same result.
use Drupal\user\Entity\User;
$user = User::load($uid);
$message_value = $token->replace($message,['user' => $user]);

There are so many nodes created using this token. So I can't edit them all with new/custom token. So Is there any way to replace the user token, without writing a custom token?
The other workaround is to use str_replace like follows, but there might exists other user tokens in the same text. so not preferable.
  $message_value = str_replace('[current-user:account-name]', $name, $message);

Any suggestions?

The current-user token will always take its data from the current user, you can't override it with parameters. See user_tokens:
if ($type == 'current-user') {
  $account = User::load(\Drupal::currentUser()
    ->id());
  $bubbleable_metadata
    ->addCacheContexts([
    'user',
  ]);
  $replacements += $token_service
    ->generate('user', $tokens, array(
    'user' => $account,
  ), $options, $bubbleable_metadata);
}

If you need to control the account object used for the token, use user instead
$message = 'Hey, [user:account-name]';
$message_value = $token->replace($message, ['user' => $account]);


Fetch Link field Label and Link separately in views-view-fields template How can I fetch label and link field in views-view-fields--VIEW-NAME-HERE.html.twig file

So far I have tried

{{ fields.field_action_link.content }} give me the anchor tag prebuilt (html)
{{ fields.field_action_link.0.url }}
{{ content.field_action_link[0]['#url'] }}

but none of them seems to work for me. I am able to retrieve all other fields including image field.

Just edit the Link field and select these two options (highlighted in screenshot)


Migrating single drupal instant to a multi-site thats live I am having a drupal site developed and ready on my local server which is a standard drupal Installation. Back on server I have a multisite setup with 3 sites all using same database with different prefix for each site. Now I want to move this site that is on local server to replace one of the site in the multi-site online.

I am confused with the following things:

How do I export the db from a single instant and import it on server?
I only have phpmyadmin access. And all sites in multisite use same db and is prefixed.
How do I export the db from localhost with the required prefix.
Does the multisite db use all the tables I have in single instant?
Will importing the local tables to multi-site db overwrite the tables thats already there or will I have to delete the tables online first and then import?

What are the best steps to follow for my problem, I saw many conflicting info online and in this community. As I am doing this on a live site, dont wan't to break it.

On the local machine:

Execute SHOW TABLES to get a list of tables.
Copy the table names into a text file, one table per line.
Use your favorite tool to transform the lines from

tablename

to

RENAME TABLE tablename TO prefix_tablename;

Choose a table prefix different from the ones you have on the server. This ensures that no tables are overwritten when you import them to the server.
Execute the resulting script on the DB of your local installation.
Edit the settings.php to use the chosen table prefix.
Export the local database. You can use Backup and Migrate but you have to make sure to also export the structure of the cache tables, but not the content. You can also use phpMyAdmin, but you should empty (not delete) the cache tables and the watchdog table first. These tables can get quite large and their content is not essential to the operation of a drupal site.

On the server:

Import the SQL file of the backup into phpMyAdmin. This creates the necessary tables and fills them with the contents from you local machine. If the file is large, you might run into issues with max_execution_time and upload_max_filesize.
Create a new subdirectory under the sites directory and copy your local settings.php file into it.
Copy any modules, themes and file uploads required by your local site to the server.
Copy sites/example.sites.php to sites/sites.php. The file sites/sites.php allows you to map Drupal sites to arbitrary paths within the sites directory. Read the comments in that file for details.
Edit sites/sites.php so that the URL of the site to replace points to your new directory within sites.

Now you can make further adjustments to your new site without damaging the old one. Problems are usually caused by different locations of modules, themes and uploaded files. These problems cannot be solved by a simple search and replace on the database, because of the way Drupal stores some configuration information (serialized PHP arrays or objects). You might want to switch the site to maintenance mode while fixing such problems.
In case of panic, remove sites/sites.php and you have your old site back.


Create views have field image with multil image style? I want create view like this

You can see this view have two image style (name are 700x700 and 263x132). I want use two image style because it's faster when the page loading.

So how can do that with views?

You can use Views "Attachment", so you can create main View to display only first two items, then you can create "Attachment" with different markup (remeber to apply this only for current format) and skip first two elements and then attach it to the main view (after it). Sorry for my english ;)


How can I set frequency of each content type with the XML sitemap module? I use the XML sitemap module (7.x-2.0-beta3) to generate the XML sitemap for my site. The problem is that I cannot set the change frequency of the content types.

In "admin/config/search/xmlsitemap/settings" I have a "Change frequency" combobox, but this is only for the front page.
I have some other content types and taxonomy tags. How can I change the frequency for them?

As far as I can see, the priority form field is added to the content type form from xmlsitemap_add_link_bundle_settings(), which is called by xmlsitemap_node_form_node_type_form_alter().

The first function, in the development snapshot, is using the following form field definitions.

  $form['xmlsitemap']['status'] = array(
    '#type' => 'select',
    '#title' => t('Inclusion'),
    '#options' => xmlsitemap_get_status_options(),
    '#default_value' => $bundle_info['status'],
  );

  $form['xmlsitemap']['priority'] = array(
    '#type' => 'select',
    '#title' => t('Default priority'),
    '#options' => xmlsitemap_get_priority_options(),
    '#default_value' => $bundle_info['priority'],
    '#states' => array(
      'invisible' => array(
        'select[name="xmlsitemap[status]"]' => array('value' => '0'),
      ),
    ),
  );

The form field for the priority is invisible when the "status" field is set to 0.


Drupal EU Cookie Compliance module conflict with theme JQuery When I first installed the module, it'd only appear in admin pages.

After some investigation, I discovered the cause was some sort of conflict with my themes jquery: jquery-1.11.2.min.js.

If I disable it, the module works. If I enable it, the module doesn't work in non-admin pages.

The error message I'm getting is

TypeError: $.cookie is not a function

I think the module is using a older version of jquery, and that API has since been deprecated in newer version. I can't update the the modules jquery without modifying the module itself, nor can I downgrade my theme's jquery.

How do I have the module strictly use its own jquery and not use my theme's (if that's the cause of the problem)?

You can use https://www.drupal.org/project/jqmulti to manage multiple versions of jQuery on your site


How to display a Views block based on the current page? I've created a new content type "banner" (title,description, image, price) that I would like to display on certain pages (limited to parent pages). I'm using the Views module and was looking for a contextual filter or something like that but I'm a noob at Drupal and can't figure out my way.

For example, I have 2 content types: rooms and activities, 2 page listings respectively my rooms and my activities and finally I've created two banners, banner-rooms and banner-activities.

How can I create a Views block which displays the right instance according to the current page ? How can I limit it to the parent page (ie: do not display the banner on rooms/roomA, only on rooms)?

Suppose there are two views

views 1 url is - http://example.com/my-rooms

views 2 url is - http://example.com/my-activities

There are two blocks -

a) banner-rooms

b) banner-activities

On the block configuration page, You need to set the visibility setting of the block for specific pages.

=>Under Visibility setting, Select the tab "Pages"

=>Select the option - "only on the listed pages"

In the text-area, fill the urls e.g- banner-rooms


Webform template suggestion doesn't work Is there a way to suggest a template in webform 3.x?

I have tried this:

$vars['theme_hook_suggestions'][] = 'webform__form__mywebform';

But it does not work.

Apply the latest patch from here: https://www.drupal.org/node/1891220
In your theme's template.php, in YOURTHEME_preprocess_webform_form(), add:

$path_parts = explode('/', drupal_get_path_alias());

$path = implode('__', str_replace(array('-', ' ', '+', '.'), '_', $path_parts));

$hook = $vars['theme_hook_original'];

$vars['theme_hook_suggestions'][] = "{$hook}__{$path}";


How to add number format function in decimal results in views 3 I am displaying some float value in my view. How can I make them till two decimal places?

Is there a way to add number_format function in view results?

You could rewrite the field output and use PHP to adjust it to your needs.

EDIT: To be able to actually use PHP in your rewrite rules you need an additional module called Views Custom Field.


How to override output (query) for views exposed filter? I have a views with exposed filter of taxonomy terms (select). It have multiple choice, and nodes output with that terms. But I want to change output of result of views for this filter. How can I do it programmatically?

It depends on what exactly you want to accomplish, some commonly used hooks are:

hook_views_query_alter
hook_views_pre_render
hook_views_pre_view
There plenty of hooks to programmatically affect the results in the Views API

Also there are plenty of Views Plugins like the Row Plugins


Views Slideshow Continuous Pager I'm in need of a little help here. I've recently begun my first website (ncpbc.us) and I began with building a Slideshow on my front page. However, the content that feeds into the slideshow uses nodequeue and will hold potentially hundreds of articles. Right now the queue holds 10 articles. The problem I'm having is that the slideshow pager only shows 5 thumbnails at a time and any new content simply makes the oldest content drop off. I'm trying to find a way that allows the user to advance the pager to the next set of 5 thumbnails.

Examples of this are at yahoo.com and http://joomlakave.com/joomla-modules/responsive-news- slider-like-yahoo. How would you suggest I go about this?

The link in the question is not working but after searching in google about the link I come across this page

If your looking for something like this then the best way will be to install view module and views Slideshow module

View Slideshow can be used to create a slideshow of any content that can appear in a view. to create a slideshow with thumbnails please check the video


How does one add a new base field to a content entity? I'm currently porting my contributed module to Drupal 8, and sometimes I realize I've chosen the wrong field type. I also know that I will need to add additional fields later on, and it would be nice to avoid having to uninstall and reinstall the module every time I do this.

I looked at Add field to existing content entity, but it did not seem to be the actual question.

My question is basically: what's the equivalent of similar D7 update.php code with D8 and entities?

<?php
function MYMODULE_update_7101() {
  db_add_field('mymodule_table', 'some_new_field', $field_schema);
}
?>

Adding fields just works. Define the new field, run update.php, it will compare the new and existing definitions and figure out that there's a new field to create.

Renaming/deleting fields works too, but only when you have no data. When you have data, then you will still need to write an update hook, or a migration. We're missing documentation on how that will look exactly, but basically, you use the same schema functions as in 7.x and then update the last installed field definitions.


setting the right views argument type I am using D6. I want to add another argument to a view, but it only needs to be a word ie: 'practice'. Which type of argument do I chose in the list of possible argument types ie:node, content, global...

It all depends on what that word is.  For example, if 'practice' is a taxonomy term name, you would choose that and Views would filter on nodes tagged with taxonomy term 'practice.'  If, however, the word was the title of a node, you would filter on node title and Views would filter on node titles equal to 'practice.'

ADDITION:

If you want to ignore the word when it comes to filtering, just use the Global Null field and it will be ignored by any queries, but will still be available as arg(#) in any script called.

ADDITION 2:

Let's say you are looking at a Views Page Display, with a path something like:

www.user1015214.com/all/the/best

that returns pictures of all the best stuff a website has to offer.  Views would have that with a path of all/the/best.  Now, let's say we wanted filter this by something, we'd change that path to all/the/best/% and then enter an argument (D6) or contextual filter (D7).  Let's say it's a taxonomy term for this example.  So now we could have something like this:

www.user1015214.com/all/the/best/views

and it would return all the best stuff the website has to offer that is tagged with the term views.  Now, let's say you want to have an easter egg feature, where if you have polite users, they get something special, so in Views, you can add another argument to the path, eg, all/the/best/%/% and in this second argument you give tell Views it is a Global Null Value.  Now, what this does is let Views know to look for an argument there, but not to use it in any of the sql it builds.  Like a placeholder.  So, now you could do something like:

www.user1015214.com/all/the/best/views/please

And Views would create the same sql statements as before, returning all the best views, but you could then access that additional argument for any custom purpose you wanted anywhere within the drupal system.  The easiest is to use the system arg(#) function:

$foo=arg(0); // all
$bar=arg(2); // best
$baz=arg(4); // please

and in your example, within the your node template file, you could do something like:

$baz=arg(4);
if ($baz=='please') {
   print '
Thank\'s for being polite! Here\'s a link to something special: ';
   print l('Pee Wee\'s Playhouse', 'http://www.peeweesplayhouse.com') . '
';
}

and then whenever someone asked nicely that additional  would be displayed along with your node.  Pretty nonsensical I realize, but I hope it explains arg()s :)


Faceted search and panels I'm using Faceted Search module and i was trying to change a display of search result with Panels.

I've enabled search-node page in admin/build/pages and added a variant with URL selection rule set to search/results/* but it looks like nothing happens.
I'm still seeing default results page instead the one which uses Panels.

Am i doing something wrong? Does anyone have any tips?
Thanks in advance

Try removing the selection rule. If the page is active and has a variant, I would expect it to work without a path selection rule.


Views: get the fields from a Paragraph without duplicate records I have a content type 'Testimonials' with a title field and a field configured as a Paragraph. I'm trying to create a view showing all the nodes of content type 'Testimonials'.

However, in the 'add field' section of the view creation page, i can only select the 'title' field. The fields that are part of the Paragraph are not selectable.

How can i get the fields from the paragraph so that i can show them in the view results?

  I tried with 'add relationship' (Paragraph referenced from
  field_dl_testimonial_components) this works but i get duplicate
  records in my view (1 record per paragraph).

Below a screenshot showing the paragraphs that are set for the field 'components main'

When working with views and entity reference revisions, which is what paragraph fields are essentially, it is preferred (in my opinion) to use rendered entities instead of relationships because of the exact issue of duplication.
Rendered entities lets you add/remove fields per view mode of the entity in a separate form.
First you must add the field of the paragraph (the one you placed on the node) to the view, choose 'Rendered Entity' and select the view mode you want (the choice of view mode depends on if you use it in other places and wouldn't want to affect appearance in these other places, or the opposite if you want to reuse appearances):

Then go to the paragraph management page, manage displays, and select your view mode (you can add additional view modes at the bottom)

From here you can configure the appearance of the paragraph like you would a content type, such as adding/removing fields.
The end result will have a view with your node titles and the paragraphs with the fields you configured in the paragraph's view mode.

Edit
In the case that a single paragraph type is needed from the field, then relationship would be appropriate here, you just need to add a filter. Add 'Type' filter and choose your paragraph type.