How to automatically install civicrm extensions in drupal+civicrm installation profile?

The current API call requires more than just the key. To enable modules as part of an install profile, you simply need to include this code somewhere in the process when it's possible to initialize CiviCRM...

  if (!civicrm_initialize()) {
    drupal_set_message(t('Failed to initialize CiviCRM'));
    return;
  }

  require_once 'CRM/Extension/Manager.php';

  $params = array(
    'version' => 3,
    'sequential' => 1,
    'key' => 'org.civicrm.volunteer',
  );

  $result = civicrm_api('Extension', 'install', $params);

As long as the Extensions Directory and ResourceURL are set in the civicrm.settings.php, you should be set.  I've been setting the Extensions Directory for Pantheon users, but still need to dynamically configure the ResourceURL https://drupal.org/node/1980088.

Rather than create a "Drupal distribution / installation profile similar to CiviCRM Starter Kit", PLEASE consider building on the CiviCRM Starter Kit by using it as the base distribution and contribute to maintaining it.  Take a look at this patch and how the latest version of OpenAtrium builds on Panopoly.

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

http://drupalcode.org/project/openatrium.git/blob/refs/heads/7.x-2.x:/drupal-org-core.make

We really need more developers working to push the patches that are still requires back into CiviCRM to keep this stable.  I hardly have time to figure out the changes with each CiviCRM release.  It has taken several years to get to the point we can install and run CiviCRM from the /profiles directory, package CiviCRM w/ drush make, and rebuild the required libraries.

The CiviCRM Starter Kit was always designed to remain a base install to build other use case specific distributions on, but I've really been maintaining this on my own so far and would love some help.

UPDATE:  I went ahead and created https://drupal.org/project/civicrm_extension_enabler since troubleshooting code in this queue is difficult.  That module enables the CiviVolunteer extensions and works a site running https://dashboard.getpantheon.com/products/civicrm_starterkit/spinup once CiviVolunteer is uploaded to sites/all/extensions

I've started an issue to change the specific extensions hard coded in the .install to be an array of extensions populated by the distribution https://drupal.org/node/2159317


How to implement pager in custom page template?

This can and should almost certainly be done entirely with the Views module (which is/will be in Drupal 8 core!). The filtering of your content by type and the value of the "top news" field can all be done with Views, along with the ajax pager. You can then use the Views attachment display type to attach those news items which do not have the "top news" box checked. You may also want to look into the Nodequeue module for ordering content in more ambiguous ways than just the most recent or whatnot, but you can also use Drupal's "sticky" setting on nodes that you want to keep at the top of the list and highlight, format them differently, etc. Views also allows you to rewrite the output of every item in the results in the UI or using tpl files. Views, my friend. Views.


In your child theme's folder create a subfolder called "templates". In this folder you should store your own templates. Just copy the system's (or parent theme's) template to your folder and modify it.
Further on, you can create more special templates, i.e. not only node.html.twig but also node--blog.html.twig.
Finally, switch on twig debugging, then you will get comments in your html like this:
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'block' -->
<!-- FILE NAME SUGGESTIONS:
   * block--bootasde-branding.html.twig
   x block--system-branding-block.html.twig
   * block--system.html.twig
   * block.html.twig
-->
<!-- BEGIN OUTPUT from 'themes/bootstrap/templates/block/block--system-branding-block.html.twig' -->

Then you always know which template was finally taken.


Programmatically save file into profile2 entity

If you are working with an unmanaged file, the following three-step process should do the trick:

Move the file (if necessary) to its final home defined by the file field on the entity.
Create a file object (see file_save_data() for some hints on how to do this) and then save it using file_save().  This will turn the file from unmanaged to managed.
Add the file reference to the file field.  You may also want to add an entry in the file usage table by calling file_usage_add().  Here is a code snippet for adding a file object to a file field on a node.

$node->file_field_name[LANGUAGE_NONE][0] = array(
  'fid' => $saved_file_object->fid,
  'display' => 1,
  'description' => '',
);

This assumes the file field accepts only one entry (index 0).


How to implement variable caching of nodes based on published date in a Drupal 6 website?

Boost could do this. Core can not due to the cache_page bin/table getting cleared on cron & node save. Boost has a cache expiration block that allows for different cache lifetimes.


The problem is that $form_state['values']['field_total'] does not exist.

First make sure that you have a field value called field_total.

Second try this code once you make sure you do $form_state['field_total']['#value'] to get the value of the field.


You can use this module https://www.drupal.org/project/like_dislike. I just tested it with a view and it works perfectly.


After searching a lot more, I came across this discussion which shows that & needs to be encoded as &amp;.
So the working link is:

 reports/aen_multi?startdate={eventdate}&amp;enddate={eventdate}

I'll leave the question up as this might help others.


Get node count for each value of a CCK Options Widgets field

Views Group By is just what you need. It enriches D6 & Views2 functionality with SQL Grouping and Aggregation capabilities. Once installed, configure it roughly along these lines:

Fields to Group On: Your Field
SQL Aggregation Function: Count
Fields to Aggregate with the SQL Function: Node NID
Fields to Sort Resultset On (after SQL Function is Applied): Your Field
Sort Direction: Descending

Please, note, this will only select those fields that have non-zero number of nodes that they are selected for. To work around that, depending on your scenario you might be able to use a taxonomy vocabulary to replace your options widget and then build a Term View type based on that vocabulary.


How can I enforce maintenance_mode at all times in a specific environment?

I think you might want to take a different approach.

The maintenance mode is now a state in Drupal 8, not a configuration. The difference is a state is a ephemeral state that's specific to the current environment (see the state API docs for more info).

As such, you might want to replace the State service with your own service class that uses the StateInterface interface if you're looking to fundamentally alter the way state behavior (which could lead to unforeseen problems).

Another tact might involve some sort one-time toggling of state (e.g. programmatically as shown above, a drush state-set / drupal state:override) based on some event (e.g. deployment of site).


Finally figured it out:
Issue derived from the language negotiation settings.
Under: admin/settings/language/configure Domain name only was configured and I switched it in the database (manually updated the variables table):

UPDATE `dinilu6`.`variable` SET `value` = 's:1:"2";' WHERE `variable`.`name` = 'language_negotiation';

Afterwards I needed to clear the cach with drush cc and then it finally worked.


How do I delete cookies when users log out?

Imlement hook_user_logout($account) and call user_cookie_delete($cookie_name).

For example:

function mymodule_user_logout($account) {
  user_cookie_delete('name');
  user_cookie_delete('mail');
  user_cookie_delete('homepage');
}


According to all messages there are two ways to solve the problem :

1) db_insert

Using db_insert() to insert data and create a specific query for postgreSQL database to get the last id after insert :

// Default insert
(...)->insert("...");

// Call this query to get last id only for pgSQL
(...)->query("SELECT currval('sequence')")->fetchAll();

You juste need to replace sequence by the key provided in your postgreSQL database.

You have to call currval right after insert to stay in the same context.

2) db_query

Rewriting the entire query with specific synthax for postgreSQL database to get the last id :

(...)->query("INSERT INTO {$table} ($fields) VALUES($value) RETURNING $id")->fetchField();

Conclusion

The first solution seems to be the best to avoid rewriting all db_insert() functions.


Is there a way to make sure an autocomplete field as an actual match?

Per the comments above, this is a bug with Entity Reference Fields and is being engaged per the Issue Queue at:

https://drupal.org/project/issues/entityreference?text=autocomplete&status=All

Patches for the Simple batch seem to work from this thread:
https://drupal.org/node/1974202

Patches for the Views reference seem to work from this thread:
https://drupal.org/node/1702172


AJAX populated filter breaks when Views Dependant Filter module added

I was able to make the second filter dependant in both ways without the need for Views Dependant Filters by adding additional logic to my hook_form_views_exposed_form_alter.

if($form_state['input']['field_commodity_tid'] === 'All')
    $form['field_keywords_tid']['#disabled'] = 1;
}

Here is the entire working code:

function dependant_keyword_filter_form_views_exposed_form_alter(&$form, &$form_state){
    if ($form['#id'] == 'views-exposed-form-annotated-bibliography-page') {

        $form['#after_build'][] = '_sort_alphabetically';

        if(!empty($form_state['values'])) {
            $form_state['input'] = array_merge($form_state['input'], $form_state['values']);
        }

        $selectedCommodity = $form_state['input']['field_commodity_tid'];
        $form['field_keywords_tid']['#options'] = _get_associative_array_from_view(
            'annotated_bibliography_dependant_keywords', // view id
            'default', // view display id
            'taxonomy_term_data_field_data_field_keywords_tid', // key field id
            'taxonomy_term_data_field_data_field_keywords_name',
            $selectedCommodity // term id of the selected shape
            );
        $form['field_commodity_tid']['#ajax'] = array(
            'callback' => '_update_keywords_callback',
            'wrapper' => 'keywords_wrapper',
            );
        $form['field_commodity_tid']['#ajax']['progress']['type'] = 'throbber';
        $form['field_commodity_tid']['#ajax']['progress']['message'] = 'Updating keywords';
        $form['field_keywords_tid']['#prefix'] = '
';
        $form['field_keywords_tid']['#suffix'] = '
';

        if($form_state['input']['field_commodity_tid'] === 'All')
            $form['field_keywords_tid']['#disabled'] = 1;
        }
}

function _sort_alphabetically($form, $form_state) {
        foreach ($form_state['view']->filter as $field => $filter) {
            if ($filter->options['exposed']  && $filter->options['id'] == 'field_keywords_tid' ) {
                $field_id = $form['#info']["filter-field_keywords_tid"]['value'];
                asort($form[$field_id]['#options']);
            }
        }
        return $form;
}

function _update_keywords_callback($form, $form_state) {
    return $form['field_keywords_tid'];
}

function _get_associative_array_from_view($viewID, $viewDisplayID, $keyFieldID, $valueFieldID, $contextualFilter){
    $associativeArray = array();
    $associativeArray['All'] = t('- Any -');
    $viewResults = views_get_view_result($viewID, $viewDisplayID, $contextualFilter);
    foreach($viewResults as $viewRow) {
        $associativeArray[$viewRow->$keyFieldID] = $viewRow->$valueFieldID;
    }
    return $associativeArray;
}


Try the Field Collection module. It's not stable yet (beta 1) but it looks promising.


How can I create an entity bundle programmatically?

Bundles are configuration.

You define a config entity with the name of the bundle of the custom entity:

class FooType extends ConfigEntityBundleBase

Then you can create a new bundle:

$bundle = FooType::create([
  'id' => 'newbundle',
  'label' => 'New Bundle',
  'revision' => FALSE,
]);
$bundle->save();

Bundles usually are not created programmatically. Most times modules put bundles in /config/install as yml files.


Use redirect after content creating and use $node

Use arg(1); - (nid of the current node) in the hook_block_view and pass it in the link

function mymodule_block_view($delta = '') {
  switch ($delta) {
    case 'your_block':
      $nid = arg(1);
      $block['subject'] = 'Share by mail';
      $block['content'] = 'share?nid='.$nid.'';
      break;
  }
  return $block;
}

Once you do that, you can make your thank_you page react on the nid argument by loading the node:

$node = node_load($nid);

and extracting from it whatever you need


entity_reference autocomplete: Allow multiple target_types

entity_reference fields do not support multiple target types, never have, also not in Drupal 7 :) So you can't have an autocomplete for that as it couldn't be stored then.

However, you can use https://www.drupal.org/project/dynamic_entity_reference, which stores entity type and ID in a field and the default widget it provides is a combination of select and auto-complete field to select the type and the specific entity.


The error message is saying that the user you set in your settings.php file doesn't have access to the database, which could happen because the password you wrote in that file is not the correct one.

Any Drupal module that accesses the database is using the database API, which doesn't require any username or password, as those are taken from a file that Drupal reads during its bootstrap.
The Forum and the Advanced forum modules are not an exception. If you are getting that error, it means there is an error with the settings.php file, or a problem with the database server.


Control fields of views on different pagination

The simplest solution I can think of is this:

In a custom module you implement hook_views_pre_render

Here's the code:

function test_views_pre_render(&$view) {
  // Current page in Views is 0 based.
  $currentPage = $view->query->pager->current_page + 1;

  // Exit early if not in the 'to be modified' page.
  if ($currentPage < 3 || $currentPage > 6) {
    return;
  }

  // Exclude the body from display.
  $view->field['body']->options['exclude'] = TRUE;
}


Views content pane not showing in panel for some users

The issue that I was having had to do with the fact that I was using Views PHP to enter PHP code as the contextual filter validator. It should have been on only one display, but it was saved in the master, and was added to all displays, including ones which were over-ridden. I removed it entirely, from the master, but it still didn't fix it. It appears that there is a bug in either the views php module, or the view module (or possibly ctools), in which the validation stayed in the views cache, even after removing it, saving the view, and clearing cache.

To fix this, I exported the view, manually removed the validation code, and re-imported.

Hope that helps the next person who might run into this very obscure problem.


$teaser is being passed in from template_preprocess_node().  DS just makes the view mode via a hook_entity_info; it doesn't wire it into the themeing system.  You need to do something like this:

function MYTHEME_preprocess_node(&$variables) {
  $variables['custom_view_mode_one']
    = $variables['custom_view_mode_one'] == 'custom_view_mode_one';
}

You could also be smart by using a entity_get_info('node'), and get all of the view modes, and set similar variables.

Note that you should already have a variable called view_mode available in your template, too.


How to hide a block entirely if it's empty

If you create blocks from the views interface itself it will not print the block if there are no results. I would recommend this method since it saves time and complexity. If you need to change the template for the block being created by the view you can do so. There is a lot of documentation on how to do that. Here is an example: Create template file for views block

In the case of what you have written below you could do something like:

$block = module_invoke('views', 'block_view', '712046d635e195e59dd93bd378e45423');
if (isset($block)) {
print "
Product Literature
";
print render($block);
}

but I would highly recommend the approach above.


How can I form a Views query that retrieves all nodes that are referenced by a node in another content type?

Ok, So the way to do this is with arguments and relationships.

Normally using the "Provide default argument" option would work but since you're not using the actual "artist" node you can't actually get the node id from the URL.

Also just an FYI, passing the title for a views argument is a bad idea because then the query is doing a lookup based on text instead of a numeric value such as the node id which is better on performance.

But anyways the solution to your problem is add the same argument to your block view as you did to your "artist" page view. This should be the node title argument. Now add a relation to your view. The relationship you want to add is the content: [name of node reference field] relationship.

Now you can add what ever fields to your view that you would want to include from the "release" content type but now you will see you get a relationship option in the field option. When you want to display fields from the "release" content type just be sure to select the [node reference] relationship.

Also we need to do one more thing. Which is getting the proper argument to be picked up by your block view. This is a bit trickier mainly because of what I mention earlier which is that you're passing the node title as an argument. So now you can edit your Node: Title argument and you should see the "option to take if the argument is not present" select the "provide default argument" and select the php code option. In there you want to paste this piece of code.

return arg(1);

Now save your view and place that block on the page and visit the artist/% page and you should now see what ever fields you want to use. This php code is telling your block view to pick up the artist/% argument from the url.

A couple of things to lookout for:

php code in the views is bad, I just mentioned that here as a quick fix to your problem.
When using relationship be sure to select the relationship option only when you want to display a field from the "related" item. In other works if you want to display the title of the related node select node title and be sure the relationship is selected. If you want to display the title of the node being passed in on the argument select node title just don't select any relationship.

Hope this is helpful, is a long post but relationships can be confusing.

Hope this helps.


Data returned from the controller is not showing in the template file

I don't know what exactly you are trying to do as var never seems to be passed an array or object but I'll give you a working example. Your controller should extend ControllerBase and use public function content() to output stuff. Also pay attention to reference the correct namespace and pay attention to upper and lower case writing as well.

module.info.yml

name: Module
description: Module description
package: Custom
type: module
version: 1.0
core: 8.x

module.module

function module_theme($existing, $type, $theme, $path) {
  return [
    'module_template' => [
      'variables' => [
        'var'   => NULL,
        'title' => NULL,
      ],
    ],
  ];
}

module.routing.yml

module.event:
  path: '/path/{user}'
  defaults:
    _controller: '\Drupal\module\Controller\Controller::content'
    _title: 'Module'
  requirements:
    _permission: 'access content'

templates/module-template.html.twig

 test {{ title }}

{{ var.getUsername }}

test 2

src/Controller/Controller.php

namespace Drupal\module\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Session\AccountInterface;

class Controller extends ControllerBase {

  public function content(AccountInterface $user) {

    return [
      '#theme' => 'module_template',
      '#var'   => $user,
      '#title' => 'Title',
    ];
  }

}

Now you can access /path/1 or whatever user ID you want to get this user's name printed.

With the Devel sub-module Kint installed you can use {{ kint() }} or {{ kint(var) }} inside the template to check out what else you can get and print.


Nothing returned from taxonomy_term_load function

Probably, this is a Taxonomy Access issue.

See taxonomy_access_query_term_access_alter().

(For the rest of the Internet, I only know this is the issue because Josh and I are working on the same codebase and I ran into the exact same issue in a completely different context.)


Dynamically filling up fields of a node in Drupal

Here is my way of doing it:

Create a Computed Field to manipulate the substring (Last Name) and store it as a field

  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.

Use Computed Field Tools to bulk update the value for the existing nodes

  The Computed Field module only updates its computed values on saves or
  on load (if no computed value is computed yet). This is not optimal
  when using computed values in lists etc., or if you should wish to
  change the logic in the computed field.

Use this Computed Field as a sort criteria in Views.


Is it necessary to use "Correct faulty and chopped off HTML"

It is not required when you are using the NicEdit though Wysiwyg.  Because, you are not using any tags in them. I you are concern to use the tags. Then, It is better to use this option. It will auto-complete and correct the faulty tags.

for example : if you forget to use the closing tags. It will add those tags.


What's inside "print render($page['content'])"? I want to style my front page in Omega subtheme

The content of the $page array is described in hook_page_alter(), where the documentation says:

  The $page array contains top level elements for each block region:

  $page['page_top']
  $page['header']
  $page['sidebar_first']
  $page['content']
  $page['sidebar_second']
  $page['page_bottom']

  The 'content' element contains the main content of the current page, and its structure will vary depending on what module is responsible for building the page. Some legacy modules may not return structured content at all: Their pre-rendered markup will be located in $page['content']['main']['#markup'].

  Pages built by Drupal's core Node and Blog modules use a standard structure:

  // Node body.
  $page['content']['system_main']['nodes'][$nid]['body']
  // Array of links attached to the node (add comments, read more).
  $page['content']['system_main']['nodes'][$nid]['links']
  // The node object itself.
  $page['content']['system_main']['nodes'][$nid]['#node']
  // The results pager.
  $page['content']['system_main']['pager']

You can use $page['content']['system_main']['nodes'][$nid]['body'], remembering there is a $page['content']['system_main']['nodes'][$nid]['body'] for each node. Check its structure to see in which way you can add a CSS class to that array.


How to make address1 field and zip code non required with Address Field module

I would use form_alter to hook into the form, identify the form element and unset or make required FALSE

eg:

mymodule_form_alter(&$form, &$form_state, $form_id){

  if($form_id == 'xyz'){
   $form['zipcode']['#required'] = FALSE;
   $form['address']['#required'] = FALSE;
  }

}


No support for links, but for what its worth heres a working snippet that uses a select.

When the select changes it triggers the submit buttons callback.
Note, you still have to define the callback on the select box as ajax.inc assumes all ajax enabled elements have one.

<?php

  $submit_name = 'product-submit-' . $node->nid;
  $form['product_id'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#ajax' => array(
      'wrapper' => 'my-form-wrapper',
      'callback' => 'product_change_callback',
      'trigger_as' => array(
        'name' => $submit_name,
      ),
    ),
  );

  $form['submit'] = array(
    '#name' => $submit_name,
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#ajax' => array(
      'callback' => 'product_change_callback',
    ),
  );
?>


How to pull in dynamic content in hook_filter_FILTER_process?

Depending on your settings, hook_filter_FILTER_process() will be invoked (albeit in a round-about way) from within the drupal_get_form() and node_load() functions.

So at the moment you're simply creating an infinite loop that PHP cannot escape from (node_load() calls hook_filter_FILTER_process(), which then calls node_load() again), hence the out of memory error.


How to remove specific meta-tag from header section of page?

I think you need hook_page_attachments_alter, which Alter attachments (typically assets) to a page before it is rendered.

 /**
 * Implements hook_page_attachments_alter().
 * @param array $attachments
 */
function my_module_page_attachments_alter(array &$attachments) {
  if (!isset($attachments['#attached']['html_head_link'])) {
    return;
  }
  $unset_html_head_link = [
    'canonical',
    'shortlink',
    'delete-form',
    'edit-form',
    'version-history',
    'revision',
  ];
  foreach ($attachments['#attached']['html_head_link'] as $key => $value) {
    if (isset($value[0]['rel']) && in_array($value[0]['rel'], $unset_html_head_link)) {
      unset($attachments['#attached']['html_head_link'][$key]);
    }
  }
}

/**
 * Implements hook_module_implements_alter().
 */
function my_module_module_implements_alter(&$implementations, $hook) {
  if ($hook === 'page_attachments_alter') {
    $group = $implementations['my_module'];
    unset($implementations['my_module']);
    $implementations['my_module'] = $group;
  }
}

excerpt from : How to unset link rel: shortlink, edit-form, version-history and revision from ?


Set expiry time for fields on content type

First feature of Node expire is:

  Perform custom actions when the nodes expire

Just write a custom action that will change field's value instead of unpublishing node.


Avoid access denied page after user logout

What you want is something called 403 redirect to Login:
https://drupal.org/project/r4032login

403 access denied messages will get redirected to the login page. I've used this before and it works nicely.


Failed opening required" symfony/class-loader/ApcClassLoader.php on line 110

Restarting php from within the VM seems to have done the trick.

sudo service php5.6-fpm restart


This configuration aligns with the options at Manage > Configuration > Development > Logging and Errors (/admin/config/development/logging).
There are 4 error level options available. The levels with their corresponding values, i.e. the actual value for $config['system.logging']['error_level'] are:

None: hide
Errors and warnings: some
All messages: all
All messages, with backtrace information: verbose

For example, to only display errors and warnings, replace your current line with:
$config['system.logging']['error_level'] = 'some';


Adding a second search for a specific content type

Maybe if I was in your case I will think about views and if the website is that heavy I will create apachesolr  view so I keep it simple flexible.


CKEditor table td style not showing in frontend

Had a similar issue for a long text field (filtered html format).

HTML tags were getting removed when switching between formats (editor was removing them).

At /admin/config/content/ckeditor/edit/Advanced (advanced is a profile name used for the filtered html format in my case), under "advanced content filter", choosing disabled solved the issue (server side filtering works, this filtering is there for the wysiwyg ux essentially).


If one block has content do not show other block

Open the "Advanced" section on the "view_upcoming_seminar" View settings page, and add a "No results behavior" of type "Global: View area". Point it to your "testimonials" View.


theme_breadcrumb() would probably be the best choice:

print theme('breadcrumb', array('breadcrumb' => $breadcrumb));

It expects the breadcrumb variable to be an array, each item of which makes up one part of the breadcrumb trail. So this array:

$breadcrumb[] = l('Home', '<front>');
$breadcrumb[] = l('Page', 'page');
$breadcrumb[] = l('Subpage', 'page/subpage');

will produce:

Home > Page > Subpage

You can also use plain text instead of links for the breadcrumb items in case you need to.


I have fixed my issue and am putting the answer here.
There were two issues that I needed to address:

The database was using RDS on AWS and I needed to enable the "log_bin_trust_function_creators" parameter group
Add TRIGGER privilege for database web user

I hope this helps someone else out there with a similar issue.


How to resolve the problems encountered when moving from local to server?

I'm assuming you're moving the files and database, as you state in your question:

Moving a site from MAMP should be pretty easy.  One thing you may be missing is updating $settings['trusted_host_patterns'] in your settings.php or settings.local.php

$settings['trusted_host_patterns'] = array(
   '^mysite\.com',
   '^.+\.mysite\.com',
   '^mysite\.local',
   '^.+\.mysite\.local',
 );

Another thing you may have forgotten to do is to clear the cache once you move the files and database.

Usually I use the drush command line utility and then from the docroot of the site, or the /sites/default directly run "drush cr".


Will Drupal & Drupal Commerce run under php-cgi?

Core in particular, but also Commerce, is extensively covered by automated tests.

Many of those are also run in a style that simulates a users journey, not only unit tests. So if you run those, you will have exercised essentially all relevant code.

There are some things that are not covered though, such as CSS and JS, although I strongly doubt those are affected by how you run the php interpreter.

Setup a Drupal instance, enable the testing module, and execute all the tests. Go read a book (as that will take a long time), and hope that you come back to all green. :)


Have you reviewed the standard method of creating menus and adding nodes to menus?  Take a look at Working with Menus.


How do I insert the node ID into a link field?

Going from node/6 page to profile/6 page (which displays products and reviews) there is a simple module that can help with this https://www.drupal.org/project/field_token_value
It will allow you to add a field PROFILE PAGE hidden from the editor and can be configured to have the value of
profile page

after that go to the content type display admin/structure/types/manage/CONTENTTYPE/display to configure where should be displayed
The field will not be available on the edit form and after saving it will hold a link to profile/[nid]
Above module works in both drupal 7 and 8
More involved alternatives
you could use https://www.drupal.org/project/linked_field and https://www.drupal.org/project/field_permissions (drupal 7 & 8)
For drupal 7 projects https://www.drupal.org/project/token_field does the same thing


To avoid overriding composer.json file you should update drupal/core using composer too.

https://www.drupal.org/docs/8/update/update-procedure-in-drupal-8

To update only drupal/core you will have something like

composer update drupal/core --with-dependencies

Which will only update the composer.json file, not overriding it.

[EDIT] Before you begin ( from documentation )

Always take a backup of your files and db before updating.
If you're using composer and version control, also commit and push composer.json and composer.lock. Use mysqldump to backup your database. Modules such as Backup and Migrate are also available.
Alternatively, you can create a .tar.gz of files and the database with drush archive-dump (however this is a legacy command, slated for removal in Drush 9, which only covers files under /web).
Read the core release notes and, as a precaution, check the project page for each contributed module, theme or plugin: some may need updating to work with a new "minor" version (e.g. 8.3) of core.  Patch releases (e.g. 8.3.1) shouldn't require this, but it's advisable to test in a development environment first.
Activate maintenance mode when updating production servers.


Updating the Answer:You can use template_preprocess_node. in your theme template.php

function YourTheme_preprocess_node(&$variables) {
  $variables['tags_tids'] = array();
  foreach ($$variables['field_tags'] as $key => $tag) {
    $variables['tags_tids'] = $tag['tid'];
  }
}

then in your node.tpl you could loop through the "$tags_tids"array, and do whatever you want.


How do I create slideshows for Youtube videos?

Follow these steps

Install and enable these four modules:[

CTools
 Views
 Views Slideshow
 Libraries

You're also going to need a single file that contains a JQuery slideshow script. This will need to be uploaded manually.

Visit link
Click the Download the Cycle Plugin link. It's hard to spot so i had highlighted it on the image below:

Download the file which will be called jquery.cycle.all.js
Access your site files.
Browse to the /sites/all/ folder.
Create a folder called /libraries/ so that the path is /sites/all/libraries/
Create a folder called /jquery.cycle/ so that the path is /sites/all/libraries//jquery.cycle/
Upload the jquery.cycle.all.js file into that last folder.

Step 2: Views

We're going to create our slideshow using Views.

Go to Structure > Views > Add new view.
Check Create a block
Choose Slideshow for the Display format
Choose 1 for the Items per page

Click Add.
Select video.
Click Apply (All displays).

Check the box which says Exclude from display.
Click Apply (All displays).

Find the Format area on the left-hand side of the Views page.
Click Settings next to Slideshow.

Scroll down to the cycle options.
Click Apply (All displays).


Webform populate text component with encoded url values

You're on the right track. It looks like you have a syntax problem with your URL param itself. If you're trying to get the value of ?this, remove the sumbitted and  [ (%5D) and ] (%5B). So your URL with the param will look like this:

http://example.com/abc?this=1

With that URL, [current-page:query:this] should return 1 (or TRUE).


Why we need the key property in the Upsert class if it is never used?

You basically said it yourself. The check is there to enforce that Upsert is used in ways that is compatible with all databases, including PostgreSQL, which needs it, as it does not actually support an UPSERT-like operation.

On MySQL, the key doesn't need to be specified as it is only supported on a table with a single unique key anyway:

https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Query!Upsert.php/class/Upsert/8.2.x

  This class can only be used with a table with a single unique index.
  Often, this will be the primary key. On such a table this class works
  like Insert except the rows will be set to the desired values even if
  the key existed before.


I believe views lets the database do the sorting, so unless your field exists inside the database, the database controller won't recognise it which is what your error message basically says.


As mentioned by @awm in the comment you have to use the DateFormatter service. But the format() method needs a timestamp so you can use strtotime() to parse the value:

$exp_date = \Drupal::service('date.formatter')
  ->format(strtotime($form_state->getValue('expire_date')), 'H:i:s');


The module Views Field View may work for you. It's worth to try.

  This module allows you to embed a view as a field in a view. A new
  field handler is made available, so this can also be used in area
  (header/footer/empty) handlers as well as rows.

  This view handler can accept arguments from fields of the parent view
  using tokens and pass them into the child view for each row. Raw or
  rendered token values can be used, as well as static values.

OR

You can even create two displays in a view - one is Page and the other is Attachment.
For your case, view-2 would be Page and view-1 would be Attachment.

You can select various settings in the attachment view such as Attach to, Contextual filter, etc.

Check this answer about an attachment view. I had a book Drupal 6 Attachment Views, but could not find a book for D7.


When using the Poster plugin for Firefox, you need to be logged into your Drupal site in another tab. Then you can use the Node Create resource. Keep in mind that you'll need to pass along the X-CSRF-Token in the header of the request. You can get the token from here, after logging in:

http://www.example.com/?q=services/session/token


You should concatenate $vars['head'] no replacing it:
Your code should be:

function mytheme_preprocess_page(&$vars, $hook) {
    drupal_set_html_head('<script type="text/javascript" src="http://use.typekit.com/12345.js"></script>');
    $vars['head'] .= drupal_get_html_head();
}

Notice the .= after $vars['head'].


If linking entities with a multi-value entity reference field, what about properties of the association?

First, there is no Drupal way. Drupal is flexible and the same result can be achieved in many ways. If you feel comfortable using join tables, go for it. In the other thread OP wanted to use a relation between entities in View, what entity references offer out of the box, where a join table would not. Therefor that was suggested.

For a situation where a relation needs to have properties on its own, you might want to look into the Relation module. It provides a relation between two entities, but the relation can have properties (fields) on its own (such as as year).

I just don't know how stable the module is for Drupal 8, but it works great in Drupal 7.

Update after the question of Asy:

The entity principle in Drupal 8 is similar to 7, so it would not change the answer much, except that the relation module for Drupal 8 is not yet finished. The problem with this specific question is that the answer is spread over 3 different posts. The combined essense is: nodes are pretty 'resource heavy' entities, as they invoke access checks, path aliasing, etc. Using them just to attach a property to a 'relation' works, but consumes more resources than a system that was designed to do just this (the Relation module, which for instance avoids the node access check and path aliasing on the in-between node). Especially when combining 3 nodes with 2 fields, this becomes SQL heavy too. Nothing SQL can't handle, just don't do it too often. So in the end is all depends on the application. If this is not a page that gets much views, you might not even notice it.

A better alternative (but I did not test nor benchmark this) might be to create a custom entity using the ECK (Entity Construction Kit). These entities are presumably lighter than nodes. Combined with Drupal 8's default entity referencing and something like Inline Entity Form to fill the field on the relation could make quite a nice interface.

In the end however you still need to join like this:

Node > entity reference field > ECK entity > entity reference field > node
  v                                  v                                  v
fields                            fields                             fields

Where the relation module (if finished) would offer something that probably looks more like this:

Node > relation > node
  v       v         v
fields  fields    fields


To tackle your exact question, let me first tell you that what happens in the form is the correct thing.

When you submit the form, it takes data, validates it and calls appropriate submit handlers to take care if the rest.
The form, once its routing is completed, does a 302 redirect to the same location so a browser F5 hit does not resubmit data.
It's a general practice to avoid double submissions.

You will need to make a module that alters the form using hook_form_alter and alter the form.

You can change form's action URL to the other PHP file or add an extra submit handler that posts data to the other raw php file using drupal_http_request.

You will find sanitized and structures data in $form_state['values'] (second param of a submit handler is usually called $form_state).
$_POST is also available at this stage.


How can I isolate *content* from *configuration* in the database?

There are different ways of passing the configuration data between various environments;

1 - Features

  The features module enables the capture and management of features in
  Drupal. A feature is a collection of Drupal entities which taken
  together satisfy a certain use-case.

  Features provides a UI and API for taking different site building
  components from modules with exportables and bundling them together in
  a single feature module. A feature module is like any other Drupal
  module except that it declares its components (e.g. views, contexts,
  CCK fields, etc.) in its .info file so that it can be checked,
  updated, or reverted programmatically.

It can be used in combination with Strongarm .

2 - Configuration Management

  ability to keep track of specific configurations on a Drupal site,
  provides the ability to move these configurations between different
  environments (local, dev, qa, prod), and also move configurations
  between completely different sites (migrate configurations) without
  the use of modules with all configuration being owned by the site.


I stored the nid from the node that's commented on in a message field and used the information in a views-view-unformatted--message.tpl.php file.

<?php if (!empty($title)): ?>

<?php print $title; ?>

<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <?php $message = message_load($view->result[$id]->mid); ?>
  <div <?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>>
   <a href="<?php if (isset ($message->field_nid['und'][0]['value'])) {
                      print url('node/'.$message->field_nid['und'][0]['value']);} ?>">
    <?php print $row; ?>

<?php endforeach; ?>


How can I update the name of a taxonomy term using hook_update_N?

honda_model.install
/**
* Fix typo of term name.
*/
function honda_model_update_8101() {
  $terms = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term')
    ->loadByProperties([
        'name' => 'Crsytal Black Pearl',
        'vid' => 'honda-color'
      ]); // load using typo
  if (!empty($terms)) {
    $term = reset($terms);
    $term->setName('Crystal Black Pearl'); // make correction
    $term->save();
  }
}

Make sure you include the block comment, as that's what gets displayed to the user when they go to /update.php
Flush all caches so hook gets pickedup.
PS: once update.php runs it gets recorded in the DB that it ran and it will not run this again. So if you later on need todo another update, you need to add a new hook and increase the number, EX: honda_model_update_8102.


You would need to use the Ubercart Attributes module, which is included in the Ubercart core module. From the Ubercart user guide:

  Products are not created equally, and in some cases the customer gets
  to decide the type of product they want. For example, your store may
  sell t-shirts, and the customer may find a design they like but need
  to get it in a certain size. In a situation like this, you will need
  to take advantage of the product attribute system in Ubercart. It lets
  you define attributes (like size), give them options (like small,
  medium, and large), and enable attributes and options on a per-product
  basis. For an example, check out the Ubercart Beanie on the Livetest.

The module allows you to set different prices per attribute and it is not very difficult to setup really.

Having said that, I prefer the Drupal Commerce way of handling product variations.


Can't filter Calendar according to event date instead of date added

You need to set up the Date argument. See Drupal therapy's video tutorial on this http://www.drupaltherapy.com/date. Also here's an output a properly configure calendar view

$view = new view;
$view->name = 'calendar';
$view->description = 'A multi-dimensional calendar view with back/next navigation.';
$view->tag = 'Calendar';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'field' => 'title',
    'table' => 'node',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Override',
    ),
  ),
  'field_date_value' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'time_only',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => 0,
    ),
    'repeat' => array(
      'show_repeat_rule' => 'hide',
    ),
    'fromto' => array(
      'fromto' => 'value',
    ),
    'exclude' => 0,
    'id' => 'field_date_value',
    'table' => 'node_data_field_date',
    'field' => 'field_date_value',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'sticky' => array(
    'order' => 'DESC',
    'id' => 'sticky',
    'table' => 'node',
    'field' => 'sticky',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
  'field_date_value' => array(
    'order' => 'ASC',
    'delta' => '-1',
    'id' => 'field_date_value',
    'table' => 'node_data_field_date',
    'field' => 'field_date_value',
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'date_argument' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'date',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'date_fields' => array(
      'node_data_field_date.field_date_value' => 'node_data_field_date.field_date_value',
    ),
    'year_range' => '-1:+1',
    'date_method' => 'OR',
    'granularity' => 'month',
    'id' => 'date_argument',
    'table' => 'node',
    'field' => 'date_argument',
    'relationship' => 'none',
    'default_argument_user' => 0,
    'default_argument_fixed' => '',
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'product' => 0,
      'event' => 0,
      'audio' => 0,
      'blog' => 0,
      'gallery' => 0,
      'gallery_image' => 0,
      'page' => 0,
      'simplenews' => 0,
      'story' => 0,
      'video' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_php' => '',
    'override' => array(
      'button' => 'Override',
    ),
    'default_options_div_prefix' => '',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
    ),
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
  ),
));
$handler->override_option('filters', array(
  'status' => array(
    'operator' => '=',
    'value' => 1,
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'relationship' => 'none',
  ),
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'event_product' => 'event_product',
      'event' => 'event',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
  'role' => array(),
  'perm' => '',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'Calendar');
$handler->override_option('header_empty', 1);
$handler->override_option('items_per_page', 0);
$handler->override_option('use_more', 0);
$handler->override_option('style_plugin', 'calendar_nav');
$handler = $view->new_display('calendar', 'Calendar page', 'calendar_1');
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'field' => 'title',
    'table' => 'node',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Override',
    ),
  ),
  'field_date_value' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 1,
      'text' => '([field_date_value])',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'time_only',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => 0,
    ),
    'repeat' => array(
      'show_repeat_rule' => 'hide',
    ),
    'fromto' => array(
      'fromto' => 'both',
    ),
    'exclude' => 0,
    'id' => 'field_date_value',
    'table' => 'node_data_field_date',
    'field' => 'field_date_value',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Use default',
    ),
  ),
));
$handler->override_option('path', 'calendar');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('calendar_colors', array(
  '0' => array(),
));
$handler->override_option('calendar_colors_vocabulary', array());
$handler->override_option('calendar_colors_taxonomy', array());
$handler->override_option('calendar_colors_group', array());
$handler->override_option('calendar_popup', 0);
$handler->override_option('calendar_date_link', '');
$handler = $view->new_display('calendar_block', 'Calendar block', 'calendar_block_1');
$handler->override_option('block_description', 'Calendar');
$handler->override_option('block_caching', -1);
$handler = $view->new_display('calendar_period', 'Year view', 'calendar_period_1');
$handler->override_option('style_plugin', 'calendar_style');
$handler->override_option('style_options', array(
  'display_type' => 'year',
  'name_size' => 1,
  'max_items' => 0,
));
$handler->override_option('attachment_position', 'after');
$handler->override_option('inherit_arguments', TRUE);
$handler->override_option('inherit_exposed_filters', TRUE);
$handler->override_option('inherit_pager', FALSE);
$handler->override_option('render_pager', TRUE);
$handler->override_option('displays', array(
  'calendar_1' => 'calendar_1',
  'default' => 0,
  'calendar_block_1' => 0,
));
$handler->override_option('calendar_type', 'year');
$handler = $view->new_display('calendar_period', 'Month view', 'calendar_period_2');
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'field' => 'title',
    'table' => 'node',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Override',
    ),
  ),
  'field_date_value' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 1,
      'text' => '([field_date_value])',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'time_only',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => 0,
    ),
    'repeat' => array(
      'show_repeat_rule' => 'hide',
    ),
    'fromto' => array(
      'fromto' => 'both',
    ),
    'exclude' => 0,
    'id' => 'field_date_value',
    'table' => 'node_data_field_date',
    'field' => 'field_date_value',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Use default',
    ),
  ),
));
$handler->override_option('style_plugin', 'calendar_style');
$handler->override_option('style_options', array(
  'name_size' => '2',
  'with_weekno' => '0',
  'max_items' => '0',
  'max_items_behavior' => 'more',
  'groupby_times' => 'hour',
  'groupby_times_custom' => '',
  'groupby_field' => '',
));
$handler->override_option('attachment_position', 'after');
$handler->override_option('inherit_arguments', TRUE);
$handler->override_option('inherit_exposed_filters', TRUE);
$handler->override_option('inherit_pager', FALSE);
$handler->override_option('render_pager', TRUE);
$handler->override_option('displays', array(
  'calendar_1' => 'calendar_1',
  'default' => 0,
  'calendar_block_1' => 0,
));
$handler->override_option('calendar_type', 'month');
$handler = $view->new_display('calendar_period', 'Day view', 'calendar_period_3');
$handler->override_option('style_plugin', 'calendar_style');
$handler->override_option('style_options', array(
  'name_size' => '99',
  'with_weekno' => 0,
  'max_items' => 0,
  'max_items_behavior' => 'more',
  'groupby_times' => 'hour',
  'groupby_times_custom' => '',
  'groupby_field' => '',
));
$handler->override_option('attachment_position', 'after');
$handler->override_option('inherit_arguments', TRUE);
$handler->override_option('inherit_exposed_filters', TRUE);
$handler->override_option('inherit_pager', FALSE);
$handler->override_option('render_pager', TRUE);
$handler->override_option('displays', array(
  'calendar_1' => 'calendar_1',
  'default' => 0,
  'calendar_block_1' => 0,
));
$handler->override_option('calendar_type', 'day');
$handler = $view->new_display('calendar_period', 'Week view', 'calendar_period_4');
$handler->override_option('style_plugin', 'calendar_style');
$handler->override_option('style_options', array(
  'name_size' => '99',
  'with_weekno' => 0,
  'max_items' => 0,
  'max_items_behavior' => 'more',
  'groupby_times' => 'hour',
  'groupby_times_custom' => '',
  'groupby_field' => '',
));
$handler->override_option('attachment_position', 'after');
$handler->override_option('inherit_arguments', TRUE);
$handler->override_option('inherit_exposed_filters', TRUE);
$handler->override_option('inherit_pager', FALSE);
$handler->override_option('render_pager', TRUE);
$handler->override_option('displays', array(
  'calendar_1' => 'calendar_1',
  'default' => 0,
  'calendar_block_1' => 0,
));
$handler->override_option('calendar_type', 'week');
$handler = $view->new_display('calendar_period', 'Block view', 'calendar_period_5');
$handler->override_option('style_plugin', 'calendar_style');
$handler->override_option('style_options', array(
  'display_type' => 'month',
  'name_size' => '1',
));
$handler->override_option('attachment_position', 'after');
$handler->override_option('inherit_arguments', TRUE);
$handler->override_option('inherit_exposed_filters', TRUE);
$handler->override_option('inherit_pager', FALSE);
$handler->override_option('render_pager', TRUE);
$handler->override_option('displays', array(
  'calendar_1' => 0,
  'default' => 0,
  'calendar_block_1' => 'calendar_block_1',
));
$handler->override_option('calendar_type', 'month');
$handler = $view->new_display('block', 'Upcoming', 'block_1');
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 1,
    'exclude' => 0,
    'id' => 'title',
    'field' => 'title',
    'table' => 'node',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Override',
    ),
  ),
  'field_date_value_1' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'time_only',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => 0,
    ),
    'repeat' => array(
      'show_repeat_rule' => 'hide',
    ),
    'fromto' => array(
      'fromto' => 'both',
    ),
    'exclude' => 1,
    'id' => 'field_date_value_1',
    'table' => 'node_data_field_date',
    'field' => 'field_date_value',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
  'field_date_value' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 1,
      'text' => '[field_date_value] <br />([field_date_value_1])',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'date_no_time',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => 0,
    ),
    'repeat' => array(
      'show_repeat_rule' => 'hide',
    ),
    'fromto' => array(
      'fromto' => 'both',
    ),
    'exclude' => 0,
    'id' => 'field_date_value',
    'table' => 'node_data_field_date',
    'field' => 'field_date_value',
    'relationship' => 'none',
    'override' => array(
      'button' => 'Use default',
    ),
  ),
  'field_teaser_value' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'html' => 0,
      'strip_tags' => 1,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_teaser_value',
    'table' => 'node_data_field_teaser',
    'field' => 'field_teaser_value',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array());
$handler->override_option('filters', array(
  'status' => array(
    'operator' => '=',
    'value' => 1,
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'relationship' => 'none',
  ),
  'date_filter' => array(
    'operator' => '>=',
    'value' => array(
      'min' => NULL,
      'max' => NULL,
      'value' => NULL,
      'default_date' => 'now',
      'default_to_date' => '',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'date_fields' => array(
      'node_data_field_date.field_date_value' => 'node_data_field_date.field_date_value',
    ),
    'date_method' => 'OR',
    'granularity' => 'day',
    'form_type' => 'date_select',
    'default_date' => 'now',
    'default_to_date' => '',
    'year_range' => '-1:+1',
    'id' => 'date_filter',
    'table' => 'node',
    'field' => 'date_filter',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('title', 'Upcoming Events');
$handler->override_option('items_per_page', 4);
$handler->override_option('use_more', 1);
$handler->override_option('use_more_always', 1);
$handler->override_option('use_more_text', 'view calendar');
$handler->override_option('style_plugin', 'default');
$handler->override_option('style_options', array(
  'grouping' => '',
));
$handler->override_option('block_description', 'Upcoming');
$handler->override_option('block_caching', -1);


Building views relationship with location

Sibling items are usually displayed with the help of two Relationships and one Contextual filter.

Create Food item Views.

You first add the Relationship for your Location field, it introduces info about the Location.

Then you add the reverse Relationship to the first one, it will use the first Relationship. The second one points back to the content that is using that Location field.

Add the Contextual filter for Node ID and make it use the second Relationship. Set it the usual way, default value and ID from URL, validate against Article Content type.

I haven't tried this with the Location field but the logic should be the same.


How do I add fields to the sidebar menu when creating/editing nodes?

The latest version of Field Group module supports putting fields into the sidebar (at least for nodes).

Field Group version >= 3.0-rc2, containing issue 2652642


getvalue() of multiple values field return only the first value

Drupal fields are represented by the ItemList class (whether they're multi-valued or not). The convenience method getValue() iterates through each item's getValue() method to build an array representation of the data value.

To retrieve a string representation of all the items in the list, you can use ItemList::getString(), which iterates through all the list items and calls getString() on each, then implodes them using ", " for glue.

So, for your example:

var_dump($user->field_mycustomfield->getString());

will output

string(14) "42, 66, 23, 77"


How to trace an Error: PDOException: SQLSTATE[23000]:

The composite primary key for field tables is entity_type,entity_id,deleted,delta,language. The error itself lists the key:

'node-4294967295-0-0-und'

You can confirm that there is a pre-existing field in the table by querying your database with a search on those values.

Also of note, your node id is at 4294967295. This is the upper limit of 32-bit unsigned integers; anything higher than that is going to start causing problems with your SQL storage.


Differentiate between same nodes in Drupal Autocomplete Search

Few Possibilities:

You can add a content-type name along with the node title when autocomplete shows the result to describe the user in which relation it goes. For e.g., "Sandy -- Content Type Name"
You can add a Nid along with the node title when autocomplete shows the result to describe the user in which relation it goes. For e.g., "Sandy -- Nid"
Nid I don't think is a good idea. But you can also set some relative name while getting result for user to know which "Sandy" should be chosen.

Hope it will take you on the right path.


In my case, this was a mistake on my part. I recently performed a find and replace on my codebase to change all my menu hooks from MENU_LOCAL_TASKS to MENU_CALLBACK.

I clearly did this ignoring case, and also did not check properly as in my template.php, I now had...

$vars['secondary_local_tasks'] = array(
    '#theme' => 'MENU_CALLBACK',
    '#secondary' => $vars['tabs']['#secondary'],
);

instead of...

$vars['secondary_local_tasks'] = array(
    '#theme' => 'menu_local_tasks',
    '#secondary' => $vars['tabs']['#secondary'],
);

Because it was now called MENU_CALLBACK in caps, it confused me and I was looking in the wrong place. It is only when I went back and diff'd my entire backed up codebase did I notice it.

Lesson Learned: Find & Replace is not always a good idea :)


How to filter articles that are in front page with taxonomy

You could just create a views filter using the taxonomy field of your article and expose it.

If you don't want the page to refresh then turn on "Use Ajax":

I think that should do it.


I have never used Opigno but since it's based on Drupal, I'd say that you should change/edit the content of a page from its corresponding form once you're logged in.

If you want to edit the HTML, than you have to look for the page templates in your theme folders. This link may help you: https://www.drupal.org/search/site/theme%20template


The image style hooks are documented here:

http://api.drupal.org/api/drupal/modules%21image%21image.api.php/7

hook_image_default_styles:     Provide module-based image styles for reuse throughout Drupal.
hook_image_effect_info:    Define information about image effects provided by a module.
hook_image_effect_info_alter:  Alter the information provided in
hook_image_effect_info.
hook_image_styles_alter:   Modify any image styles provided by other modules or the user.
hook_image_style_delete:   Respond to image style deletion.
hook_image_style_flush:    Respond to image style flushing.
hook_image_style_save:     Respond to image style updating.

Nothing for the actual image generation process, if that's what you're looking for.

See image_style_deliver for the details on the image generation


How to tell Stringsoverrides module to replace text only in specific module?

String Override works for the strings defined inside t(), t() takes context as one of the parameters, for example

1. t('May', array(), array('context' => 'Long month name')
2. t('May', array(), array('context' => 'Abbreviated month name')

Both the strings are 'May', if you replace it would be changed across, but t() function also takes context, so if you provide the right context, only that instance of sting will be replaced. String overrides also takes the context while replacing the string, you have to make sure the string you want to replace in a moudle passes through t() and with what context.

Other way could be if its a variable then do a variable_set()

What I prefer is to patch the module, keep the patch in patches folder. To me string replacement is not mission critical peace, after next update release we re-do our patch.


Use custom content entity theme suggestions in own module?

To make a theme suggestion work in the module folder you need an additional theme hook:
function offer_theme($existing, $type, $theme, $path) {
  return [
    'offer' => [
      'render element' => 'elements',
    ],
    'offer__full' => [
      'base hook' => 'offer',
    ],
  ];
}


as far as i can see there are 2 options, and both would involve writing some custom code.

1st, provided that you have enabled product revisions, when saving the invoice, save that particular revision number and then load your product based on that revision.

2nd, would be to add product fields that you are interested in, to you invoice (price, desc etc.) and based on the product attached save those in form validation handler


How to get rid of an extra space in a twig date field template?

You can also use Trim, if doesn't work please check this answer.


I changed $file_list to an actual list, ["."] and source_siteroot to "sites/default/files/old-sites/" and that gave me a valid path. Also profile_id to import_html_current_profile_id();

Thanks!


In the Aggregator module, limit number of items per feed

This might not be the right way to do it but I solved this by using template_preprocess_aggregator_feed(&$variables) and then slice the items using array_slice().

My items were stored at $variables['content']['items'] but there were two other hashtag variables stored in the beginning of the array so I had to add that to the total count.

function template_preprocess_aggregator_feed(&$variables) {
  $number_of_items = 5;
  $variables['content']['items'] = array_slice($variables['content']['items'],0,2 + $number_of_items);
}


I would use the Migrate module with the CSV as a data source.


created element with ajax ,not act autocomplete

Try this.

$form['azlocation'] = array(
'#type' => 'select',
'#title' => 'location',
'#options' => array(1, 2, 3),
'#default_value' => 1,
'#description' => t('select your news location.'),
'#ajax' => array(
  'event' => 'change',
  'callback' => 'country_select_f',
  //'path' =>'roadtonowhere',
  'wrapper' => 'city-term',
  'method' => 'replace',
  'effect' => 'fade',
 ),
 );
 $form['field_terms_city'] = array(
 '#type' => 'textfield',
 '#title' => t('select city (optional)'),
 '#prefix' => '
',
 '#suffix' => '
',
 );
 return $form;
}
function country_select_f($form, $form_state){
   $form['field_terms_city']['#autocomplete_path'] = 'user/autocomplete';
   return $form['field_terms_city'];
}


Display a field of one content type in another content type

You have a choice of modules for this:

References
Entity Reference
Relation

Any one of those modules will allow you to create a field on your Loan Offers content type that references a Bank node. Then you can use Views/custom code/etc. to display the bank's image on the loan offer's node pages.


Hide block if content is empty not working

Up solution :

In views, go to "advanced". At the very bottom, see "hide block if view is empty". Change it to yes and it will work.


Entityform is spanning the full width of the browser. Well beyond page margins

The problem lies in the somewhat flawed structured and logic of the theme. The best solution to this would have been to restructure the theme and apply the styles for the container class, which handles most of the content layout, to a wrapper in the page.tpl.php template so that all pages get the same layout no matter content.

However, as the theme is as it is, and you don't have much Drupal knowledge I would instead recommend to apply the "container" class to the form element, or wrap the form in a div with that class. Unfortunately you can't do that in the UI.

The fastest and easiest way to fix this is to add the class to the form using hook_form_alter().

In your /sites/all/themes/chesapeake/template.php file, add:

/**
 * Implements hook_form_alter().
 */
function chesapeake_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'volunteer_form_entityform_edit_form') {
    $form['#attributes']['class'][] = 'container';
  }
}

And then clear the cache at Configuration > Development > Performance. That should add the "container" class to the form and display the page correctly.


Increasing PHP memory limit (Possible Drupal override?)

Drupal does not edit any php config settings. The memory_limit and what php.ini it is using depends on how your server is setup, there could be something else that is overriding your php.ini you are trying to set. You should use phpinfo() to find out what php.ini it is using and make sure the last occurrence of memory_limit is set to what ever you want.


jQuery seems to be the way to go if you want to manipulate the markup output by Quicktabs.

 /*we only want to append the data once hence the condition */
 if (!($('#quicktabs-my_tabs .quicktabs-tabs li img').length > 0)) {
   $('#quicktabs-my_tabs .quicktabs-tabs li.first').prepend("");
   $('#quicktabs-my_tabs .quicktabs-tabs li.first').next().prepend("");
   $('#quicktabs-my_tabs .quicktabs-tabs li.last').prepend("");
   $('#quicktabs-my_tabs .quicktabs-tabs li a').append('');
 }

Note that this example works for 3 tabs - it should be modified for your setup.

In order to make the whole quicktab a clickable link, add appropriate css to the span inside the a element, as described in this post: Make a div into a link


file upload using CCK not showing nid reference

So lets say you have a content type X. You add a field Y to X to upload a file (using filefield or image etc) then you will find the nid and fid in the field table created by cck.
This table will be something like content_field_Y which should have the nid and fid that you desire.

Update: To clarify the column name will not be simply fid, but will be the machine name of the field suffixed with _value, _nid etc.


Override specific configuration keys in settings.local.php

The key for $config is the config name, not the module. This should work:
$config['shield.settings']['shield_enable'] = FALSE;


Change the default upload file location for a particular content type

You might find some information about how to code changing file names in the File Path module.

File (Field) Paths allows you to automatically sort and rename your uploaded files using token based replacement patterns to maintain a nice clean filesystem.


Query a list of field values of a node in drupal 7

Consider using the Forena module, it comes with all sorts of reporting features. And all sorts of hooks if you want to use them in your own custom modules.
Here is an excerpt from its Community documentation:

Forena Reports is built of the idea of using SQL to get data out of a database and use XHTML and CSS to format it into web reports.
It is designed to leverage existing knowledge of HTML, CSS, SQL and JavaScript to help you create rich interactive web reports.

Disclosure: I'm a co-maintainer of Forena,
I hope this does not violate the site's policy on self-promotion.


Can't access links in block_view_alter hook

Those hooks are unfortunately not very useful; I don't really know why they work like that. The actual block view didn't happen yet; that's in a preprocess. You'd need to add another preprocess that runs later.

However, for your specific use case, why not use the hook that's designed exactly for this? hook_language_switch_links_alter()?


How to create flexible number of columns in a Views table display?

To my knowledge you can't do this with (only) the Views module. But your question seems like a variation of something related to processing log messages. Digesting these messages is quite a challenge. That's why I've come up with my own "custom" report, as illustrated in this screenprint:

Within the "Report Execution Parameters" (collapsed in the screenprint above), I specify the search criteria of the log messages to be retrieved (like severity, User name, etc). And the red numbers are hyperlinks to get a drill down report of the specific messages for which I wanted more details (= to display the actual watchdog entries).

Some more details about the above table (to explain why it is similar to your question):

Think of the columns (with headers starting with "Msg Type:...") as your "Title XX". While each row (= different message) is like your User "1", "2", "3".
If there wouldn't have been any errors with (say) "Msg Type: Ajax" or  "Msg Type: page not found", then the corresponding column wouldn't have been created.
The red numbers (hyperlinks) are aggregated data, which in your case would correspond to commentXY (blank cells in your case would indicate that there is no such comment for user X and title Y).
Some columns (like "Msg Type: Error" or "Msg type: PHP") contain a value for multiple rows.

Refer to my answer to "How to gets analyts and generate visual reports from sessions?" for more details about creating reports (tabular displays) as in the above screenprint.

In case you wonder "How did you do that?" (without checking out my answer in the above link): There's a module for it ... it's called Forena ... And the clue in this specific case is to use Forena to create a "Crosstab table".

Disclosure: I'm a co-maintainer of the Forena module.


Possible to save plain text value when entity reference doesn't exist?

Instead of adding an user entity field you can create a normal text field and then use formalter function to make it an auto complete.

The steps would be as follows.

Create a custom module.

First you would need to create a menu item to get the list of users to do that you can create a hook_menu function

function module_name_menu() {
  $items['userlist/autocomplete'] = array(
    'page callback' => '_module_name_autocomplete',
    'access arguments' => array('you can define the permissions here'),
    'type' => MENU_CALLBACK
  );
  return $items;
}

The next step would be to create the call back function.

function _module_name_autocomplete($string) {
  $matches = array();

  // Some fantasy DB table which holds cities
  $query = db_select('users', 'u');

  // Select rows that match the string
  $return = $query
    ->fields('u', array('name'))
    ->condition('c.name', '%' . db_like($string) . '%', 'LIKE')
    ->range(0, 10)
    ->execute();

  // add matches to $matches
  foreach ($return as $row) {
    $matches[$row->name] = check_plain($row->name);
  }

  // return for JS
  drupal_json_output($matches);
}

The last step would be to create a form alter function to

function module_name_form_page_node_form_alter(&$form, &$form_state, $form_id) {
  $form['field_name']['#autocomplete_path'] = 'userlist/autocomplete';
}

This would change your textfield into an autocomplete field. you would also be able to enter any other name as well.


passing a user id to user_is_logged_in function

If you look at the docs you'll see the function comment:

  Determines if the current user is logged in.

Emphasis mine.

So the function simply isn't supposed to do what you want to use it for, you'll need to write something custom

It's pretty easy though, see Get all logged in users in Drupal for some inspiration.


How do I count the number of Facebook likes in articles?

Probably setting the layout to button_count will do all the magic ;)
This should be available in settings, or can be changed in MYTHEME_preprocess_fblikebutton.

Or use modules which provide this functionality, like:

social_counters and shariff have D8 versions.
views_fb_like counts your likes. (D7 only yet)
facebookshare implements this in combination with social_stats. (D7 only yet)


How can I resolve these errors when updating the module?

It sounds like Drupal Console someone was installed improperly, based on the duplicate class name error.

Can you try removing the /pathto/commerce8/vendor directory. Then run composer install once more. That'll fixup all third party dependencies, hopefully resolve this.


Drupal 8: Multi-sites in subdirectories not working

Download latest  D8 version.
Extract and navigate into the
directory: /drupal/sites/
Create sites.php duplicating example.sites.php
Add the code to sites.php

$sites = array(
      'dogs.multisite.local' => 'dogs',
      'multisite.local.cats' => 'cats',
    );
Create two folders named 'cats' and 'dogs' on the sites folder.

/drupal/sites/dogs/
/drupal/sites/cats/

The /drupal/sites/default/ site will have default files we need to copy into each of our sites. Copy these files using the cp command in the sites directory:

cp default/default.settings.php dogs/settings.php
cp default/default.settings.php cats/settings.php
cp default/default.services.yml dogs/services.yml
cp default/default.services.yml cats/services.yml

Setup virtualhost

hosts

 127.0.0.1  multisite.local

httpd-vhosts.conf

<VirtualHost *:80>
ServerAdmin webmaster@multisite.local
DocumentRoot "/opt/lampp/htdocs/drupal"
ServerName multisite.local
ServerAlias    *.multisite.local multisite.local.*
ErrorLog "logs/multisite.local-error_log"
CustomLog "logs/multisite.local-access_log" common
</VirtualHost>

Once it is done, you can start the installation of your new website in a multisite context from the urls:

   http://dogs.multisite.local/
   http://multisite.local.cats/


How can I let authenticated users rebuild caches?

Yes, that's what I created Rebuild Cache Access for.

  This module provides a new permission: rebuild cache access. Every
  role with this permission set will have a nice and big "Rebuild Cache"
  admin toolbar button. Clicking this button simply fires
  drupal_flush_all_caches(). That's all.


In sent message, the user name is not displaying

This is currently working as designed. The message listings do not show your own username as you obviously are a recipient as it is displayed for you. It is however a limitation of the current system that when you send a message to yourself, no recipient is shown.

You can alter the sql query and remove the exclusion of the current user for the sent list, but then it will always show the current user there.

There are some ideas on how to make the whole listings more flexible but that's quite a bit of work and needs time that I currently don't have.


How can you create a list of referenced nodes in a view?

Got there in the end, thanks to a combination of the (very nice and helpful) Baysaa and keva. This was the method that got there in the end:

Contextual Filter: Content: Nid (set to "do not use a relationship"; default value of "content ID from URL")
Relationship: Content: Related Nodes (with "require this field")
Then, I went to Format and changed Show: Content to anything else. Then I changed it back to Show: Content - this allowed me to select the relationship I defined above (I couldn't define the relationship here without changing Show: Content to something else first).


How to write PHPUnit test for any function that has external dependencies?

The code is dependent on Drupal's service container existing, and thus a container needs to be instantiated and used. This is possible in PHPUnit tests using the \Drupal::setContainer() method, and creating a container object.

use Drupal\Core\DependencyInjection\ContainerBuilder;

protected function setUp() {
  parent::setUp();

  $this->account = $this
    ->getMockBuilder('Drupal\user\Entity\User')
    ->disableOriginalConstructor()
    ->getMock();

  // Create a new container object.
  $container = new ContainerBuilder();

  // Add a service into it.
  $container->set('current_user', $this->account);

  // Let Drupal use your mock container.
  \Drupal::setContainer($container);
}


field_get_items gives me an array of node IDs. Can I filter these by type without using node_load()?

Unless you have a map of those ids -> types somewhere outside the DB to reference, no, it's not possible. You could go directly into the node table yourself, of course, and avoid node_load specifically, but there's no way to do it without a db hit.

It's impossible to say how performant a View would be without knowing how your site is built, server specs, traffic info, and so on. The best thing to do would be to try it and benchmark.


What are the pros and cons of using Acquia Drupal install packages?

Boris Mann once described Drupal as a big box of Lego. Acquia Drupal is just a bigger box of Lego.  It still doesn't do anything out of the box, it just gives you more pieces.  Given how much stuff went into Drupal 7 core it is mostly redundant - download core, views, wysiwyg and admin and you can start building good sites.

In terms of pros for Acquia Drupal I'm struggling a little.  The first is that it helps inexperienced users get onto the Acquia Network.  The other is that you don't have to download everything, but this is also a con as you get everything Acquia thinks you need.

One of the biggest cons as I see it is that they dump all the modules under modules/ which is considered bad practice in the Drupal community.  Not only is this annoying if you decide to switch back to stock Drupal + contrib or Pressflow + conrib, but it teaches users bad practices from day 1.

I must admit I played with it once and decided against using it.  These days I assemble my code using drush make as it gives me only what I want and I'm not dependent on a third party to provide security releases after a module is updated I can just update my make file and reroll my stuff.

[rant]These days the community has moved on to building true distros, not just throwing more Lego pieces in a box.[/rant]


The "links__node__node" theme function is not defined from any Drupal module. If a module defines a theme function matching that name, then Drupal will use it; otherwise, the function that is going to be used is theme_links().

In your theme, you can define both the theme functions. The difference is that theme_links() is generally used, while the other theme function is used just in a specific case.

function themename_links__node__node(&$variables) {
  $links = $variables['links'];
  $attributes = $variables['attributes'];
  // …
}

function themename_links(&$variables) {
  $links = $variables['links'];
  $attributes = $variables['attributes'];
  $heading = $variables['heading'];
  // …
}


Not load JS formatter field used Views Infinite Scroll

add an ajax complete function to your js code.

Ex:

$( document ).ajaxComplete(function() {
    // Do stuff here when ajax loads.
});


How to enforce minimum height and width for image while resizing anything larger?

Reformatting an image won't happen on upload, it will happen on display of the content. If you want to reject anything less than 480x480, set that as the minimum in the field's setting and don't set a maximum size.

To resize the image, be sure there is an image style set to resize an image to 480x480 (which is included by default in Drupal 8). Then under the "Manage Display" field of the content type, click the gear next to the image field and select the desired image style that you want displayed.


How can I add a Pathauto pattern for a content type depending on a reference field?

Right beneath the pattern input you have a link that opens a popup to let you choose tokens to be put in the pattern. For field values it normally goes along the line of [node:field_foobar:value]. Depending on the field value you may also consider to either provide your own custom token or to alter the current token with an alter hook to replace the value with an URL-safe value (like to prevent the URL contains an Emoji for example).


I'd recommend against accepting this right away even if it works for you because I suspect it isn't the best answer, but I ran into this same problem and I ended up just overriding the template with raw HTML like so:

Copy core/modules/views/templates/views-view-fields.html.twig to the appropriate location in your own theme (e.g. themes/custom/mytheme/templates/views/views-view-fields.html.twig for me)
For each variable output in the loop add the raw filter, e.g. {{ field.content | raw }}
Clear your caches and refresh the page to see the result

I think this should be okay since any HTML that comes from the views fields should already be filtered of anything harmful (and I believe this is more or less how it used to be done - take a look at the old PHP views templates) but if someone knows better please do correct me in the comments.

EDIT: I noticed one of the related questions (Drupal 8: HTML isn't rendering, HTML tags are being printed) has a link to this issue: https://www.drupal.org/node/2363423 which I believe is related, so this workaround may soon no longer be necessary.


How to properly name tpl file for webform-submission-navigation.tpl.php?

Copy webform-submission-navigation.tpl.php to your active theme templates directory
Clear Drupal Cache
Add a php condition in above tpl to render your link only for node 139

Code you need to use in above tpl...

<?php
 if ($node->nid == 139) {
    print l('You Link Title', 'link/path');
 }
?>


Symfony\Component\HttpFoundation\Response is never cached

Return a cacheable response. For example
use Drupal\Core\Cache\CacheableResponse;
use Drupal\user\Entity\User;

  /**
   * A route returning a CacheableResponse object.
   *
   * @return \Drupal\Core\Cache\CacheableResponseInterface
   *   A CacheableResponseInterface object.
   */
  public function cacheableResponse() {
    $user = User::load(1);
    $response = new CacheableResponse($user->label());
    $response->addCacheableDependency($user);
    return $response;
  }

From Drupal\dynamic_page_cache_test\DynamicPageCacheTestController.
There are multiple ways to add cache data to the response object additional to the one used in the example.
You can use addCacheTags()/addCacheContexts():
$response->getCacheableMetadata()->addCacheTags($tags);
$response->getCacheableMetadata()->addCacheContexts(['route']);

The route cache context is by the way not necessary in a controller because it depends already on the route.
Or add cacheable metadata contained in a render array
use Drupal\Core\Cache\CacheableMetadata;

$response->addCacheableDependency(CacheableMetadata::createFromRenderArray($build));

See also How to handle cache metadata in a cacheable response? and How to get cache metadata from nested render array when returning response?


There's somehting funky happening on this line:

$output .= drupal_render($val['uid'. $key]);

$val is not an array, you'll need to rethink your PHP code. Do a Google search for "Warning: Cannot use a scalar value as an array" and you'll see a bunch of cases where other users are dealing with the same issue. As an example:

PHP : Cannot use a scalar value as an array

EDIT:

Looking at your code again, this line looks suspect:

unset($key,$val);

You're in a loop that is using these values. Applying an unset could result in the issue in addition to the point I made above.


I forgot to enable the module  mimemail_compress. After enabling this it was solved.


Is it Possible to Change "Edit Permissions" Based on a Field Value on that Node?

I think you can achieve this by implementing hook_node_access() with a check on the particular field.

https://forumone.com/ideas/programmatically-restricting-access-to-drupal-content has a very similar use case (except the field there is an entityreference field to users, but you get the gist)


You can use the Devel module, and enable page show devel page query.
Devel:

A suite of modules containing fun for module developers and themers.

Helper functions for Drupal developers and inquisitive admins. This module can print a summary of all database queries for each page request at the bottom of each page. The summary includes how many times each query was executed on a page (shouldn't run same query multiple times), and how long each query took (short is good - use cache for complex queries).

Also a dprint_r($array) function is provided, which pretty prints arrays. Useful during development. Similarly, a ddebug_backtrace() is offerred. See full demo.

Accelerate development of your site or module by quickly generating nodes, comments, terms, users, and more.


How to allow content tagging by anonymous users?

You could use the Flag module, and allow it to be used by anonymous users also, as described in my answer to "How to display a flag to anonymous users?". Create a flag for each tag you want to allow for anonymous tagging, and assume you label such flag like "Tag with TagABC".

Use the Rules module to create 2 Rules Components:

a 1st Rules Component (say "Approve Tag suggestions") that performs 2 Rules Actions, and looks like so:

apply the tag TagABC
unflag it again (to remove the flag "Tag with TabABC").

a 2nd (similar) Rules Component (say "Reject Tag suggestions") to only unflag (=remove the flag "Tag with TabABC") anything that is considered as "rejected".

Use the Views Bulk Operations (VBO) module (which depends on the Views of course) to create a VBO list of anything flagged like "Tag with TagABC", and use this during your review process to mark (select) anything that was flagged and that should be considered as "approved" (similar approach later on for anything to be considered as "rejected"). The actual "operation" to be performed (by VBO) is to execute either of both Rules Components described above. For more details on how you can use VBO and Rules together, refer to my answer to "How Do i implement an alternative for the Privatemsg Bulkmail module?".

4 commonly used modules (which can be used for plenty of other use case), and some relatively easy site configuration to be performed. That's it.

Limitation: what is above does NOT support FREE tagging (= invent your own new tags) for anonymous users (which may lead to tons of tags, used only once). Maybe a compromise could be to have a link to "suggest your own tag", via some form shown on a block? Other idea (never tried): flags are fieldable, so add a select list field to an extra flag (say: "pick your flag"), and use the "Select (or other)" module to allow such additional tag to be suggested.


Escape forward slashes in hook_update_n() descriptions for display on update.php

Given that line 1161 of includes/update.inc is this:

$description = str_replace(array("\n", '*', '/'), '', $func->getDocComment());

(replaces new lines, asterisks and forward slashes in the doxygen comment with blank strings, everything else is considered to be the update description)

I'd say you have two options:

Use an HTML entity:

/**
 * Create alias for node&#47;add&#47;video-submission.
 */

Patch the offending line with something like:

$description = str_replace(array("\n", '/*', '*/', '*'), '', $func->getDocComment());


Drupal fullcalendar integration -> JSON Formatting?

The solution was pretty straight forward actually.

I replaced the jscon encode and json output like this:

drupal_json_encode($json);
drupal_json_output($json);

And now it runs smooth :-)


Class not dynamically loaded in custom module

To use namespaced classes in Drupal 7, you can use one of these modules:

https://drupal.org/project/xautoload
https://drupal.org/project/registry_autoload

One reason for choosing one or the other may be if you have other modules that also depend on one of those modules.

Otherwise I guess it is largely a matter of taste.

One difference is that xautoload is more convenient during development, because newly created PSR-4 classes are immediately available without rebuilding the class registry.

On the other hand, it does a lot of things which you probably don't need right now, and the code looks complex.

Of course you could do some profiling to find out which is faster, but as always you would need to be careful what you measure and what you compare. I currently cannot tell you which one is faster, or better for memory.

There is also the alternatives module that can help to have only one of those enabled, instead of both.

Disclaimer: I am the author of one of these modules, and I am subscribed to the autoload tag on drupal.stackexchange.com.


How to create conditional checkboxes that hide each other?

Simple solution: Don't use 2 fields with checkboxes, use one field with radio buttons.


How to list all taxonomy terms in a vocabulary followed by associated node titles in Views

Create a view in following way,

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

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


The password is stored as a hash, upper/lowercase differences result in a different hash.

The only possible way I can think of is if you always convert the password to upper/lowercase before it is used, both when registering and when logging in. But that sounds error prone to me.

Also, if the passwords are already stored in the database, then there is no way to do it.


Your form is a ContentEntityForm, so you need to use the entity form builder service, e.g.:

$entity = /** create or load your entity **/
$entity_form = \Drupal::service('entity.form_builder')
  ->getForm($entity, 'default');


Adding additional fields on user registration page (first name, last name)

You just need to goto:

Administration » Configuration » People » Account settings » Manage fields