formatting a select custom field I created a custom field with the following definition:

  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {

    $value = isset($items[$delta]->value) ? $items[$delta]->value : '';

    $element += [
      '#type' => 'select',
      '#title' => $this->t('Select item'),
      '#options' => [
        'empty' => $this->t('Select an item'),
        'key1' => $this->t('value1'),
        'key2' => $this->t('value2'),
        'key3' => $this->t('value3'),
      ],
      '#suffix' => '

',
      '#attributes' => ['class' => ['edit-custom-field-widget']],
      '#attached' => [
        'library' => [
          'custom_field/my_js_custom_field',
        ],
      ],
    ];

    return ['value' => $element];
  }

In Formatter class I wrote this:

  public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = [];

    foreach ($items as $delta => $item) {
        $elements[$delta] = [
          '#type' => 'html_tag',
          '#tag' => 'p',
          '#value' => $item->value,
      ];
    }
    return $elements;
  }

When I show content type item with my custom field I see

"key1" but I would like to see: "value1"

Is it possible to show "value1" directly or are other operations necessary?

For the select Form element, the array key is the value, and the array value is the display of the option. That's why you're getting 'key1' for example.
If you want to achieve your goal you can write it this way:

'#options' => [
    'empty' => $this->t('Select an item'),
    $this->t('value1')->render() => $this->t('value1'),
    $this->t('value1')->render() => $this->t('value2'),
    $this->t('value1')->render() => $this->t('value3'),
],

Although this doesn't seem right :D
Also, while you're at it, you should check 'Select' form element documentation as you shouldn't add 'empty' value but rather use the '#empty_value'and '#empty_options' properties.


Automatically generated invaild URL In admin/config/search/redirect/404, I found a lot of invalid url, it's a lot of additional "products" on our url, for example, News/products/products/products/products/products/products;
LED-Replacement-Lamps/LED-RGB-Lights/products/products/products/products/products/products/products/products/products;

The "NEWS" is our Contents, but "LED-Replacement-Lamps/LED-RGB-Lights/" is 301 redirect I do by "URL redirects”. So I want to know it's the problem of "URL redirect" tool or others?

I have check the patterns,but i did not find the issue.
I want to know why there is many links with additional "product" repeat again and again?

Problem is in your  pathauto Patterns, go to admin/config/search/path/patterns1 and check your pattern, it seems you have a pattern that when each time  the content edited Url  added to your Url Alias again.

I guess something like this exists there

 products/[node:url]


How to hide menu settings at content creation for specific content types I'm adding menu items programatically. Is it possible to get rid of this for specific content types?:

In my situation it's just one more way to break something, and is totally not needed :) .

You can use hook_form_alter placed in a custom module or in your theme's template.php file for this. Try something like this:

function THEME_OR_MODULE_NAME_form_alter(&$form, &$form_state, $form_id) {
  // There's probably an easier way to check if it's an update or create form.
  if (!$form['nid']['#value'] && $form['type']['#value'] == 'page') {
    unset($form['menu']);
  }
}

I'm not completely sure about the $form['type']['#value'] value. You might want to double check that so you won't get any false positives on other pages which also has forms. You could use $form_id for this, but that variable is unique for each content type.


Can you prevent a module from being disabled? Is there any way to prevent Admins from disabling a module. Is there anything that can be done via code?

If you're looking for a per-module solution, add the required property to its .info file.

  As of version 7.x, modules and themes may specify that they are absolutely required and should never be disabled by adding required = TRUE. These modules will be enabled automatically during install. In most cases it should only be used with the Drupal core required modules (e.g. Node, User, etc.).


Remove certain content types from search There are certain content types such as book pages that I don't want to appear on the search results page.
I found example code implementing this on drupal 7 here

/**
 * Implements hook_query_alter().
 * removes content types defined in the excluded_content_types array from search results
 */
function hook_query_alter(&$query) {
  $is_search = FALSE;
  $excluded_content_types = array(
      'product',
      'billboard',
    );
  foreach ($query->getTables() as $table) {
    if ($table['table'] == 'search_index') {
      $is_search = TRUE;
    }
  }
  if ($is_search) {
    foreach ($excluded_content_types as $content_type) {
      $query->condition('n.type', $content_type, '<>');
    }
  }
}

However I want to implement this in 8.
Is there a way to exclude certain content types from search results?

UPDATE: I've also attempted to restrict the search types from within the search-result.html.twig however it does not seem like I have the content type variable available.

{{ attach_library('classy/search-results') }}
{{ title_prefix }}

{{ dump(info_split) }}

  {{ title }}

{{ title_suffix }}

  {% if snippet %}

{{ snippet }}

  {% endif %}
  {% if info %}

{{ info }}

  {% endif %}

When performing {{ dump(info_split) }} it does not show content type as an available variable.

Configuring search is easy with Search API. Excluding node types from indexing is one of its basic config options.

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

When you set up your index and go to the configuration page, you can exclude bundles (types).


View with multiple value fields: suppress display of repeated column values My content type has two fields: field_title and field_related. The field_related is of type Entity Reference and its cardinality is set to unlimited.

The view should display the title, updated date and all related titles, in tabular form, like this:

Title          Updated      Related
=====================================
Chapter 1      2014-01-01   Note A
                            Note B
                            Note C
Chapter 2      2014-02-02   Note A
                            Note B

Currently, it is displaying this:

Title          Updated      Related
=====================================
Chapter 1      2014-01-01   Note A
Chapter 1      2014-01-01   Note B
Chapter 1      2014-01-01   Note C
Chapter 2      2014-02-02   Note A
Chapter 2      2014-01-01   Note B

I tried grouping, but it divided the whole table into separate tables.

I see no point here in using aggregation here (maybe I am wrong..)

What is the solution to this?

The answer was obvious. For the Entity Reference type of field, don't use fields from the referenced entity (like e.g. "Title") from a relationship. Instead, use the field from the main entity (without relationship). As a result, it displays a title of the referenced entity anyway and not an ID or something.

But in this case, the field gets "Multiple Field Settings" config group, which should be set to "Display all values in the same row". I saw that solution before, but in my view there wasn't this config group at all. That's because I used a field from relationship, which apparently doesn't have a setting for multiple value, because in that entity it's single value, it's a title.


How to display visitor's country flag depending on the visitor's IP address? How can I display Visitor's country name and flag and depending on his IP address in a block?

The Smart IP module can give you the user's IP address. The following code should give you a block, assuming you have flag images whose file names match the country code, e.g. "ie.png" for Ireland and those file are in "/sites/default/images".

function mymodule_block_info() {
  $blocks = array();
  $blocks['flag'] = array(
    'info' => t('Country flag')
  return $blocks;
}
function mymodule_block_view($delta='') {
  $block = array();
  switch($delta) {
    case 'flag' :
      $block['content'] = _flag_block_view();
      break;
  }
  return $block;
}
function _flag_block_view() {

  // Get the IP address
  $smart_ip_session = smart_ip_session_get('smart_ip');
  if ($smart_ip_session['location']['country_code']) {
     $code =  $smart_ip_session['location']['country_code'];
     $output = '<img src="/sites/default/files/images/' . strtolower($code) . '.png />';

  else {
    $output = "Nothing";
  }
  return $output;
}

The above is a simplistic solution. In practice you might want to make better provision for country codes and/or flag images not being available,  add alt and/or title attributes to your  tag, etc.

Also bear in mind you will need to choose a source of IP geolocation data. See this answer for info on that. And, remember geolocation data is not guaranteed to be 100% accurate.


Call Drupal PHP function from Javascript? I'm trying to get the content of an article and display it using AJAX by replacing the content of a div with the new article's content. In order to do this I want to make an asynchronous jQuery call to a PHP page that simply outputs the article's body. However, this PHP function needs access to the Drupal PHP functions in order to operate properly. Where or how can I create a PHP file that will have access to these functions in a Drupal install?

To get data from Drupal's database and/or produced in PHP, you need a page callback (in a custom module) that output the data without the full layout rendering. This is easily doable by printing the content of the page directly in your page callback instead of returning it.

If you want to retrieve nodes in AJAX, you can also use the Services module which provides JavaScript callable endpoints (REST, JSON over HTTP) for nodes, users, taxonomy terms, etc.

If you still want to work outside Drupal, in a standalone script, you should include Drupal's include/bootstrap.inc and call drupal_bootstrap() function to initialize Drupal environment (connect to database, load modules, session, etc.). You can select the phase to bootstrap depending on what you need from Drupal.

chdir('path/to/drupal/root');
require_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Drupal is fully loaded here, you can access everything.


How can I preprocess pager links for a view display? I've created a custom Drupal 7 block view that uses a mini pager. I need to display the pager-previous and pager-next links as images, and replace the pager-current link with some text. Do I need to create templates for these three links? Do I need preprocess functions for each of them? What are the naming conventions for these templates and functions? They would be tied to a particular block display.

For the mini pager, the Views module uses its own theme function, theme_views_mini_pager(), which uses the more generic theme functions for the previous, next, and current links. There isn't a template file for that theme function, as the theme function itself is returning the markup.
With hook_preprocess_views_pager(), you could change the values contained in $vars['tags'][1] and $vars['tags'][3], which by default are the '‹‹' and '››', but those are passed to a theme function, which means you are someway limited in what you can do.
$li_previous = theme('pager_previous', array(
  'text' => isset($tags[1]) ? $tags[1] : t('‹‹'),
  'element' => $element,
  'interval' => 1,
  'parameters' => $parameters,
));
if (empty($li_previous)) {
  $li_previous = "&nbsp;";
}
$li_next = theme('pager_next', array(
  'text' => isset($tags[3]) ? $tags[3] : t('››'),
  'element' => $element,
  'interval' => 1,
  'parameters' => $parameters,
));
if (empty($li_next)) {
  $li_next = "&nbsp;";
}
$items[] = array(
  'class' => array(
    'pager-previous',
  ),
  'data' => $li_previous,
);
$items[] = array(
  'class' => array(
    'pager-current',
  ),
  'data' => t('@current of @max', array(
    '@current' => $pager_current,
    '@max' => $pager_max,
  )),
);
$items[] = array(
  'class' => array(
    'pager-next',
  ),
  'data' => $li_next,
);

You can implement hook_theme_registry_alter() to replace that theme function with your own. In this case, you have complete control over the output; you could even tell Drupal to use a template file.
Keep in mind that theme_views_mini_pager() is used for mini pager of every view. For what I can see, there isn't any value passed in $vars that makes understand for which view the mini pager is output.
Given the lack of documentation on the values passed in $vars, I would check what is passed in $vars. It may be that one of those values is the view ID, or machine name.
The values documented in the theme functions for the previous, next, and current links are the following.

element: An optional integer to distinguish between multiple pagers on one page
interval: The number of pages to move backward when the link is clicked
parameters: An associative array of query string parameters to append to the pager links


How can I display a view's count in a navigation item? How can I display a view's count in a navigation item?

I have a view the displays a list of stories (a content type) and I have an item in a menu that links to that view. I need to display the number of items returned by that view next to the menu item that links to it on all pages of the site.

The solutions I've thought of so far have been:

Add a block to the view and have that blocked displayed in a hidden area on all pages and then use the total_rows or num_rows property of the view's object. The disadvantage of this is that this view then runs on every page possibly causing performance issues.
Add a block (or some other type) to the view that calculates the count and have that displayed by the menu item some how. But I haven't been able to figure out how to do this. I tried using the "Use aggregation" setting but I get a "broken/missing handler" error when using an "Aggregation type" other than "Group results together" in Sort or Filter criteria.

Any help with this would be much appreciated.

This is running on Drupal 7.7.

I know only how to get it with codding.
You can define in your module function, which gets total rows count from your view. And you can use drupal cache system for result, but actually you can use Views cache for it.
Something like that:

/**
 * Executes View to know rows count
 */
function testm_get_view_items_count($view_name, $display_id, $args) {
    $count = &drupal_static(__FUNCTION__);
    if(!isset($count)) {
        if($view = views_get_view($view_name)) {
            $view->set_arguments($args);
            $view->get_total_rows = true;
            $view->execute($display_id);
            if(isset($view->total_rows)) {
                $count = $view->total_rows;
            }
        }
    }
    return $count;
}

You can add cache_set/cache_get as Lulabots showed, but then you need to think about when to do flushing you cache.
You can use this function in THEMEORMODULE_preprocess_menu_link() function in Drupal 7. Here I showed example.
This code works on D7.


Public:// doesn't work I am trying to code as follows:

  $uri='public://admin/myfile.txt';

but if (file_exists($uri)) fails

the complete path

  $uri='/var/www/html/www.mydomain.com/sites/default/files/admin/myfile.txt';

works and passes (file_exists($uri))

drupal_realpath('public://') returns /var/www/html/www.mydomain.com/sites/default/files

What am I missing here?

The path 'public://admin/myfile.txt' is not a real path (because of the 'public://'-part, which is a drupal-custom), it's a stream-wrapper-path (see link at end of answer).

  file_exists() can only process real-paths and registered stream-wrapper-paths

This means for you: Either your Drupal-installation didn't register it's custom stream-wrapper or your server-isp deactivated the stream-wrappers on your server/account.

You should check your php-config for Filesystem and Streams Configuration Options:
http://www.php.net/manual/en/filesystem.configuration.php

More info on php's stream-wrappers:
http://www.php.net/manual/en/wrappers.php

BTW: Registering of custom stream-wrappers is supported by PHP 4.3.2+


How to theme webform component? I want to change the order of a webform component. This creation of a webform component:

$component = array(
      'name' => key($question_name),
      'form_key' => $key,
      'type' => $form_type,
      'mandatory' => 0,
      'weight' => $weight,
      'pid' => 0,
      'extra' => array(
          "items" => "1|1\n2|2\n3|3\n4|4",
          "multiple " => FALSE,
          "aslist" => FALSE,
          "description" => $question['description'],
        ),
);

Gives me the following display result:

Name of component
1 - 4 radiobuttons
Descriptiontext

But I want to move the description text over the radiobuttons:

Name of component
Descriptiontext
1 - 4 radiobuttons

How can I change the order of the output?

What I was searching for was:

function THEMENAME_webform_element($variables)

https://drupal.org/node/1157306


What is the best practice or easiest way to import product types from their content type derivatives? I'm new to Drupal Commerce, and I want sell clothing articles. For the clothing articles, I created a view with a content type including fields like name, price, article-number, etc.

Now I want to create a shop with product types. Can I just import the content types into the product types or do I have to add new product types and then create all the articles over again? What is the best way to add products to my shop?

It sounds like you have your "content type" confused with your "product type". With Drupal Commerce, you need to add "products" which are of a particular "Product Type". Each product has at least a title, a SKU, and a price, but you could have more fields like size for example. You then attach the products to a product display node so that they are visible in the shop. A Product Display Node is a regular content type node with a product reference field that points to the product type entity.

You may be asking why do I need both product entities and product display entities? This is for the situation where you have multiple products included with each display. So if you have a clothing article that comes in small, medium and large sizes and is also available in either blue or green, then you have 6 SKUs for this clothing article. You would have 1 product display entities with product references to the 6 SKUs.

Your content type that is the product display should include the name of the product, the general description of the product and maybe an image of the product, etc. Your product type will have the SKU, the price, and any other fields that are unique to the SKU.

Read more (and probably better constructed examples) at the Commerce Guys site


How To resolve Broken/Missing Handler with Independent views query backend flag links patch? So, I'm trying to do something that should be relatively simple, show a catalog of products based on a search index to provide a faceted search with some flag links.

I have a view based on a search index of product displays with a required relationship to
Indexed Commerce Product: A bridge to node referenced by field_product_sku in order to pull the images into the view. My Flag is set to my custom product type (posters), and I can confirm it works.

The closest I've come was using patch #1Independent backend query flag links mentioned here. This works in so far as I now have access to Commerce Product: Flag Link for Entities, and Content: Flag Link for Entities, both of which give me a broken/missing handler message.

So: 1) How do I fix this? 2) is there a better way to get my Flag links into the Search view?

Try disabling views cache. I believe it should remove broken/missing handler.


Client specific prices Is it possible to have client specifik prices for products in Commerce?
This should be an option with specific clients that has an agreement with the company. Everyone else will pay the ordinary prices.

Yes, it's possible. I would recommend using role based pricing. Customers who deserve the special pricing should be given a specific user role. Then on the product type, add a secondary price field used specifically for users with that role. Finally, add a product pricing rule that checks to see if the order owner (i.e. commerce-line-item:order:owner) has the user role. If so, you should swap in the price value from the secondary field using "Set the unit price to some amount" and fetching the secondary price using the appropriate token. Remember that you'll have to first run an "Entity has field" condition on the line item to find its product reference field and again on the product to find its secondary price field.


Drupal differential db restore I have several Drupal sites hosted on my shared hosting server. Each site has a dev, test and production instances, with separate Docroots and Apache Vhosts and separate mysql db instances. Not using features module.

Production db has real live data in it. dev and test dbs have dummy data. But as per the development workflow, if a new module has to be installed the developers do it in dev and test instances. That creates a new table and some records in the dev/test db instances.

Now that if they want to have the same module installed in the production site, I want them to able to run an operation via web which takes that particular table/data to the production instance from dev/test.

To explain bit more: This is what I need.

A ==> Test Site

B ==> Production Site ==> Real Data

A new module is installed in A. This creates a table and some records in A. We should be able to take that particular table/data from A and import into B keeping all the B's data consistent. And we dont really know what table is created in A. This is all done by the developers.

In a nut shell. B = (A U B) i.e. B should become A Union B

I tried mysqldiff but that works only for schema but not data.

Ideas please.

This is a huge question.

I just can share my experience

First i export mysql data from live site with Backup and Migrate module.

I do restore it in my dev site. In this dev site, i beware to not send infortunetly emails, so i install Reroute email module. (great because the settings are not in database but in settings.php file)

Then i make my own dev on localhost with real datas

Depends if your have the abilities to do that, and if the datas are not so confidential to do so.

But to stick with your question, db diff is impossible is guess. And you have to upload the new module files and enabled them manually (or with drush). Settigs in drupal are totally encapsulated in db


Image title in Views replacement patterns? I can not seem to find the title token for images in replacement patterns in D8 views. In D7 it was [field_image-title] but there is no title option in D8. I have tried {{ field_image_title }} and {{ field_images-title }}.

The replacement pattern is:

{{ field_image__title }}

See this screenshot from Views:


domready is not defined I'm building my own theme to be used with Angular 4 and can't tell where/why Drupal is deciding to import jQuery.

Here's the code for my theme, loosely based off this Angular 1 theme:

ng.info.yml

name: ng
type: theme
libraries:
  - ng/base
description: 'An theme that makes Angular do all the work'
core: 8.x

ng.libraries.yml

base:
  version: 8.x
  js:
    js/inline.bundle.js: {}
    js/polyfills.bundle.js: {}
    js/styles.bundle.js: {}
    js/vendor.bundle.js: {}
    js/main.bundle.js: {}

ng.module

<?php
function ng_theme() {
  return array(
    'ng_view' => array(
      'template' => 'view',
      'variables' => array('title' => NULL),
    ),
  );
}

ng.routing.yml

ng.view:
  path: 'ng'
  defaults:
    _title: 'Drupal Angular'
    _controller: '\Drupal\ng\Controller\DrupalNgController::viewDrupalNg'
  requirements:
    _permission: 'access content'

src/Controller/DrupalNgController

namespace Drupal\ng\Controller;
use Drupal\Core\Controller\ControllerBase;
class DrupalNgController extends ControllerBase {
  public function viewDrupalNg() {
    $build['myelement'] = array(
      '#theme' => 'ng_view',
    );
    $build['myelement']['#attached']['library'][] = 'ng/inline.bundle';
    $build['myelement']['#attached']['library'][] = 'ng/polyfills.bundle';
    $build['myelement']['#attached']['library'][] = 'ng/styles.bundle';
    $build['myelement']['#attached']['library'][] = 'ng/vendor.bundle';
    $build['myelement']['#attached']['library'][] = 'ng/main.bundle';
    return $build;
  }
}

templates/view.html.twig

<html{{ html_attributes }}>
  <head>
    <title>Angular app</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="HandheldFriendly" content="true" />
    <meta name="apple-touch-fullscreen" content="YES" />
  </head>
  <body>
    <app-root></app-root>
  </body>
</html>

Given you didn't install any contrib modules nor themes, dozens of Drupal core modules requires Jquery to function. You'll have to check what modules lists JQuery as a dependency.
Search in core/modules and core/themes directories for core/jquery and you'll find out what module/theme is adding it and disable it.

For example "contextual" module needs it.


Subscribe to issue queue In drupal.org I would like to get email notification when an issue that involves me is updated with a new comment. Right now I have to subscribe per project from URL http://drupal.org/project/issues/subscribe-mail/[project-name] by clicking "own issues" checkbox. This is pain. Sometimes I fail to subscribe to a project and I get no follow-up comments in email.

Is there a page where I can enable it globally to subscribe to all my own issues as against doing it for individual project ?

There was a page that would allow you to subscribe to different projects, but it has been removed.
The only way to subscribe to project issue queues is the one you described.

The link to subscribe to the issue queue of a project is present in two places:

in the project page, in a block to the right side
in the project issue queue, under the issue queue title


DraggableViews questions If I followed the README.txt in the module and created a view with a sorting field as instructed, should I be able to drag the items around with a four-way cursor, and then Save? I do see the Save button, but no ability to drag...

Also, is there a way to have DraggableView come into play for a view which uses display mode (teasers) rather than fields? (I do have my own CCK field named "weight", which I could make use of and get away without DV, so it's just a question of how to make admin UI easier).

Yes, you should get the four-way cursor and be able to drag stuff around. My own experience has been that DW for D7 is quite buggy. We use a particular commit in NodeStream's makefile, you could try to work from that one, as we do our best to keep well working versions in that make file.
I don't think you can use a View mode, but must use fields. I could be wrong though.


Form - Submit hidden field (select) Should be pretty straightforward but I am kinda stuck. I am prepopulating a mandatory field's value according to the URL, so I want to prevent the field from showing up, but not in a CSS level.

hide() and #access do not seem to submit the field leading to a validation error. Any clues on how would I go about doing this?

P.S. not a field of #type => hidden. An actual field. A select list if you want.

Comment trail clarifications:
1) the field is an entity field, a user field
2) the field is mandatory
3) the field is prepopulated using #value and #default_value (for safety (?))
4) the field should not be either visible or editable
5) I'd like to avoid adding a hidden and/or value field myself and write another submission/validation function since the user_register one works just fine. I want to use the value that the field has upon the form's rendering taking into consideration point 4.

Since Drupal 7, Field API is in core so you don't have to worry about Fields when editing a node form. In Drupal 6, you have to add an #after_build function to do this.

You need to create a hook_form_alter function to alter the user_register_form. (or hook_form_FORM_ID_alter).

I can't remember the structure of form fields. Install devel module and you can see the entire $form array nicely.

 <?php
    function mymodule_form_user_register_form_alter(&$form, &$form_state) {
      dpm($form); // Make sure you have Devel module installed.
      $field_name = 'field_myfield';
      $value = $_GET['somekey']; // populate this var from the URL params as you mentioned in your question.

      if (isset($form[$field_name][LANGUAGE_NONE][0])) {
        if (empty($value)) {
          $form['#access'] = FALSE;
          drupal_set_message(t('Please use correct URL'), 'warning'); // in case the value is not set, hide the form and issue a warning.
          return;
        }
        // #options is an array like this: array('key' => 'value', 'key2' => 'value2');
        // Make sure you set the key of this array in $value. if your $value is a value, you'll need to array_flip and find the key instead.
        $form[$field_name][LANGUAGE_NONE][0]['#type'] = 'value'; // this element will not be rendered at all
        $form[$field_name][LANGUAGE_NONE][0]['#value'] = $value; // this value will be passed to $form_state['values']
      }
    }

Calling the form using drupal_get_form DOES fire all form_alters as necessary.
If you are trying to use this form with a direct menu router, set page callback in the menu router item to drupal_get_form and
array('user_register_form'), as the page arguments


Advanced search in Multidomain - Multilanguage catalog webpage Drupal 7 I have a quite complex products database. I have migrated most of the content and hierarchy into Drupal taxonomy, content type and relationships scheme. However, I am not sure if I will be able to configure some Advanced search module to look for products according to name of product, category (taxonomy) and other intrincate parameters. Can you advice some module which is easy to configure and write own MySQL search strings?

There are at least two options. You can use the Views module to expose search filters on the products.

If you have access to an Apache Solr search server you can use some of the modules that integrate with Solr for advanced searching.


What is the purpose of Views "Attachment", "Content pane" & "Context"? I've just made a Views for a content type.

In one views, I need a page for the content type and a preview of 4 newest posts on the front page.

Page is not the problem. For front page preview, I just confused about the purpose of "Attachment", "Content pane" & "Context". I don't know which one to use for front page preview.

"Context" does not have more link, and "Content pane" is not for Panels pane since Panels module is disabled.

The Attachment option is to create yet another view that you can attach before and/or after any of the displays on your current view.

An example of its use is if you enable the taxonomy views the taxonomy pages are overwritten by the view and if you were to add a couple of extra fields like images, description, etc to your taxonomy term you can the use an attachment to display it as the header of each taxonomy page.

The EVA module extend this functionality by allowing you to attach views to content types and other entities.

The other two I have never use, but:

Here is an explanation about "Content pane":

http://drupalize.me/videos/basics-views-content-panes


View sorting becomes arbitrary with grouping field? The setup:

A view that lists out nodes containing study abroad Program information. Its format is Unformatted List. There is a Grouping field of Country (which is a field on the Program content type). The list is sorted by Country (asc) and then Program title (asc).

There are exposed filters (via Better Exposed Filters) for a few of the fields from the Program content type... one of which is Country. These filters are exposed in a block that's included on the view page.

The Problem:

When you perform a search via the exposed filter block with multiple Countries selected, the sort order seems arbitrary. The grouping (by Country) works, but the Countries are listed out of order... not alphabetical asc or desc... just arbitrary.

Worth mentioning: any other search using any of the other exposed filters, but not selecting any Country values, works fine.

What's going on here? Why does sort get wacky when searching by Country... which, coincidentally or not, is also the grouping field?

It seems that disabling "Reduce duplicates" on the exposed filter of the grouping field will bring the sort back in order. So, in this case, unchecking "Reduce duplicates" on the exposed filter, Country (which is also the grouping field) did the trick.


How do I display user picture from profile fields? Possible Duplicate:
  How can I display a picture from a field as the user picture rather than the drupal default with user-picture.tpl.php?

I would like to display the user pictures in message list and message view. The images are uploaded through a user profile field, and not the default Drupal account picture field.

How do I do this in Drupal 7?

Private Message displays the user picture via a theme('user_picture') so I'd just copy the user-picture.tpl.php template out of the system user module directory and into your theme's and modify it to display your field instead of the default.  You may want to put additional logic in there so that it doesn't do this everywhere but that's up to you.


404 Error report getting refreshed? For some reason CRON seems to be deleting all 404 errors reported at

admin/reports/page-not-found

Is there any way to disable the deleting of the 404 errors?

Watchdog entries are deleted by dblog_cron(), if the dblog_row_limit variable is greater than 0.

To stop them being deleted, set the dblog_row_limit variable to 0.


Breadcrumb displays overridden page label instead of node title Configuration:

Drupal 8.1.5
Panels 8.x-3.0-beta4
Page Manager 8.x-1.0-alpha23
Layout plugin 8.x-1.0-alpha22
Panelizer 8.x-3.0-alpha2

Main menu:

About

Team
Technology
...

When visiting page /about/team, the breadcrumb shows Home About.

With Page Manager, I have overridden the default /node/{node}, and created a couple of panel variants based on path.

With this configuration, when visiting page /about/team, the breadcrumb shows Home Node view. So, instead of the node title for the /about page, the label of the custom page managed by Page Manager is displayed.

Is this a bug or expected? How to fix it?

This is an issue related with page_manager module.
Check out the d.org issue queue https://www.drupal.org/node/2665328


Modify custom module's setting.yml without reinstalling I have made a simple custom module in Drupal 8, in which I use a settings file (config/install/my_module.settings.yml)

I have one entry, let's say

module:
  key: 'qsdqsd'

So when I install the module, I can use this entry in my controllers.
But if I need to modify anything in this file (adding an entry, for instance...) I can't use it in my controllers (config->get(module.new_entry) returns NULL) unless I uninstall then reinstall the module.

drush cache-rebuild did not help neither.

What am I missing?

You can try the module config_sync, there you can update the site's configuration from your custom module.

afaik there is no official way to update configuration from an updated module.


Simple markup field module I'm looking simple markup field (similar to Field Hidden which would provide dummy field which can place hold some html code (such as field title and its description without showing any field).

So basically something equivalent to this Form API element:

$form['markup'] = array('#markup' => 'foo bar');

but as a proper field (so no custom coding or styling involved) which can be attached to Entityform.

As suggested by Clive, there is a Static field which provides a static text that can be configured on a per instance basis via Field API.

Just enable the module and use Field UI to add and configure the field.

There is also another module, called: Pseudo field which allows you to render an extra field as a real field (with field label).


Drupal 8 - url rewrite don't work on beta12 after installation I don't have this problem on Drupal Beta 11, but with Beta 12, after installation, urls don't work, example :

The requested URL /Beta12/admin/structure was not found on this server.

Why I have this bug please ? It's a Drupal 12 problem ?
Thanks.

Last Drupal 8 Beta release don't have .htaccess.


Editing contents of custom block referenced in paragraph type, doesn't reflect changes in node where displayed So, I have a Custom Block type, let's call it Sidebar Links Block. In an Article, we have a Sidebar paragraph type that allows quite a few different entities, one of which is the Article Sidebar Links paragraph type.

The Article Sidebar Links ¶ type (which is one of the fields of our Article type) contains a single entity reference to a Custom Block type, the aforementioned Sidebar Links Block.

If I change, say, the Title of the Sidebar Links Block, that change is not reflected in the paragraph type's output. In other words, when viewing an Article where we changed the contents of one of the referenced Custom Block types, it still shows the old contents, before the change.

Even clearing the Drupal caches in the usual way, does nothing. What I have to do, instead, is:

Edit the Article
Move any ¶ type up or down, then move it back (this triggers the form's JS that detects changes, allowing you to re-save with essentially no real changes)
Re-save the Article

This finally causes the Title to update in the Article Sidebar Links ¶ type where the Sidebar Links Block is referenced and displayed.

Is there any way around this? Currently, whenever we update a Custom Block, we have to apply this manual fix to every single Article where it's referenced. I have a hunch that it has something to do with cache tags, but I don't know enough to be able to investigate. Does anybody have any ideas as to how this can be fixed?

So the way that I ended up fixing this, was to use Twig Tweak to output the content block directly, like so:

{{ drupal_entity('block_content', content_block_id) }}

This ends up bypassing Drupal cache. Barring a better fix, this is the one I'm going with.


Cannot log in to Drupal running alongside WordPress multi-site I have a Drupal site (7) that I've migrated to a new server. I have a WordPress multi-site install on this server that looks like this at the moment:

example.com
store.example.com

I used to have a forum.example.com, but frankly the available WordPress forum options leave a lot to be desired, so I moved my old Drupal forum instead of migrating.

The issue is that I cannot log in to Drupal, from any account, even using a Drush generated link.

I've tried clearing caches, truncating session tables, adding $base_url in the settings.php file, setting session.name on both the WordPress and Drupal installations.
I'm at a loss. I've been banging my head against this for 4 hours now. I switched to a secondary domain (forum.example2.com) and it works perfectly; so all I can come up with is that there is some sort of collision between the two frameworks with either the sessions or the cookies.

Why cannot I log in with any account? How can I fix this?

Edit:
To be clear, if I change Apache to point a different domain to this installation, everything works fine. I installed Flarum in place of drupal, and am able to log in. This problem is only present when the two frameworks are drupal and WordPress, and they are subdomains of the same main domain

Setting the user manually also doesn't work, for example:

global $user;
if(ip_address() == 'my.ip.address'){
   $user = user_load(1);
}

If I dump the user object after this it is loaded, but the next page load still leaves my as an anonymous user.

I bet it was the COOKIE_DOMAIN in wp-config.php:

define('COOKIE_DOMAIN', 'sub.mydomain.com');

Define it without leading dot.


Can I have a body apply to a different page than the current content type? I want to give the editor user a good experience where he/she can edit everything about one news article in one content type. I have a gallery that takes a content type where he/she can place an image, caption, and a link. I desire this link to be pointing to the page where the body wysiwyg would be. I would like the body to be in the same content type, just displayed on a different page.
I hope I am clear. Thanks for your help!

I'm not totally clear on what you are asking, but I will try to help anyway (and maybe with more clarification I can help further)).

It sounds like you have a gallery content type. Do you need these gallery images for anything else? Because it also sounds like you want an image to show up on the news article page. If that is the case, why not just have fields for the images, caption, and link in the news article content type? That way, when the person goes to edit the news article, everything is write there - both the fields related to the news article itself as well as the fields related to the gallery ones. I feel like this would make more sense to the person editing it anyway.

And then if you still need a separate gallery or something using the images that have been added, you can still use the images in the news article content type to make a separate view.


Is there a view for top selling products, including product kits? I'm looking for a view to list top selling Ubercart 3 products and product kits.
It would be a BIG plus if the view can include an image field and a taxonomy field.

I have checked this articles but didn't get what I'm looking for

http://drupal.org/node/1339910

Ubercart most selling product in drupal 7

Thanks

easyrec for ubercart module provides the functionality for most selling products(most bought items) and it also provide the following options as blocks.

Available Blocks

easyrec: other users also bought
easyrec: other users also viewed
easyrec: recommendations for user
easyrec: most bought items
easyrec: most viewed items

  To use the "easyrec for ubercart" module a shop owner needs access to
  an easyrec server. It's possible to register a free easyrec account at
  http://easyrec.org/ if the owner cannot host his/her own. After
  creating an account on the easyrec server and a 'tenant' account for
  the specific shop, the shop owner just copies the tenantId and apiKey
  into the drupal module's administration interface to enable
  recommendations for the ubercart shop.


Node authors notified by email when a comment is added using trigger module - node token not getting My goal is to send a notification email to the node author when a new comment is added. For this i am using trigger module. But didn't get the node author mail id.

Any one experienced in it?

Maybe you can try these module
http://drupal.org/project/comment_notify

Video tutorial
http://drupalize.me/videos/notify-author-comments
http://drupalize.me/videos/notify-comment-reply


Hiding admin (user/1) account How can I hide the main administration account from authenticated users? I have created a new role and created a new admin account.

You can implement hook_menu_alter() in a module to alter the access callback used for the "user/%user" path.

The code I would use is the following one, which is generic enough not to take assumptions about the access callback already set, and the arguments passed to that access callback. This means the code will work even if there is another module that alters the access callback for the same path.
The same code would work for Drupal 6, once you replace any occurrence of user/%user with user/%user_uid_optional.

function mymodule_menu_alter(&$items) {
  if (isset($items['user/%user'])) {
    array_unshift($items['user/%user']['access arguments'], $items['user/%user']['access callback']);
    array_unshift($items['user/%user']['access arguments'], 1);
    $items['user/%user']['access callback'] = 'mymodule_user_view_access';
  }
}

function mymodule_user_view_access($account, $callback) {
  $args = func_get_args();
  // Remove $account and $callback from the arguments.
  unset($args[0], $args[1]);

  $uid = is_object($account) ? $account->uid : (int) $account;

  // 1
  if ($uid == 1) {
    // The user ID is 1; only that user can view that user account.
    return ($GLOBALS['user']->uid == 1);
  }
  // 1

  // Let the previously set access callback decide who has access to the user account.
  return call_user_func_array($callback, $args);
}

The code would not allow any user to access the super user account, except to the super user. If you want to allow the users with the permission to administer users to see that user account, you can replace the control statement commented with // 1 with the following one.

  if ($uid == 1) {
    // The user ID is 1; only that user can view that user account.
    return user_access('administer users');
  }


Link url paths change from within the 'user' area I have made a block for a footer which contains 2 simple links. The html code is as follows:

PRIVACY-POLICY&nbsp;&nbsp; TERMS &amp; CONDITIONS

The links work fine as long as i click on them while being anywhere on the website BESIDES the user profile. BUT, as soon as i try to click the links while in my user profile, instead of the URL pointing to "/privacy" or "/terms", the system appends a "/user/" path before the link. So the link becomes as follows: "/user/privacy" and "/user/terms". If i try to access it i get a Access denied.
I cannot for the life of me! figure out why this is happening.....
What am i missing?
Drupal 7

Thanks for your help!!

Modify your href from

and

to

and

Notice the slash. That means the path is relative to your base url instead of being relative to your current path.


Create custom links for private message in OG group I am using the module private messages to let users send messages to groups and other users. I would like to create a link where the recipient info is automatically filled with the Group title on the new message page.

Did any one try to work with private messaging groups and create the autocomplete links  ?

There is a module for private message in group but it is sandbox module and for Drupal 6 only. You can customize it for Drupal 7

Just check this Sandbox

And refer this discussion also, it has nice roadmap regarding implementation of entire module. http://drupal.org/node/612664


What is the difference between hide() function and unset()? What is the difference between hide() and unset()? I want to hide some elements, I found hide() and unset(), but I don't know which one I should use.

hide() and unset() are not same.
hide() is a Drupal function and unset() is a raw php function.

unset() simply destroys a variable.
For an example,

<?php
$name = 'Drupal';
unset($name);
print $name; // this will result an error as $name is no longer set. `isset()` will return FALSE.

hide() does NOT destroy the variable. It's useful to mark some render-able array is already rendered so it will not be rendered again.

it simply adds/replaces the given argument's #printed to TRUE so drupal_render or render() won't execute the theme functions again - instead, it will use cached version if available.

A sample use case of hide() would be to hide comment form in a node template and show it somewhere else in the template. You will also find it useful when altering pages or blocks. Do NOT unset() a render array if you want to use it somewhere else.

If you want to hide some specific form element from the user but still want to keep the form structure, set #access of the element to FALSE.

hide()

drupal_render()

unset()


Migrate files from directory to Drupal using Migrate I have a folder with a large amount of files in. I need to migrate this into Drupals file system so I can then reference them in the content.

The ID of the file is the actual name e.g. 1234.jpg

What's the best method of doing this? I think I have the destination method set using MigrateDestinationFile()

I could write a script to create an xml document which defines every file in the folder and then extend the XMLMigration class and use that but it seems a bit overkill? Are there any source methods that would help with this?

If you are now using migrate_extras to set media as destination, you can take a look to the following links:

An useful example to import images using media as destination
A thread on drupal.org that deals a question very similar to yours


Send an alternative email to an anonymous user who placed an order I have 2 cases:

A registered and logged in user who gets an email after he placed an order. In that email he gets the token [message:message-commerce-order:view-url] where he can view his order.

An anonymous user gets the same email but: But I'd like to delete the token [message:message-commerce-order:view-url] because an anonymous user can't see that page because he needs to log in.

How do I send an alternative mail to anonymous users after they place an order?

You could look to the Rules module to accomplish this, though a lot depends on how you are managing orders (Commerce module?).

If using Rules you could set conditions for user role to determine which email they get.


Notification + Subscription: Can this combination recipe be used to create notification system similar to Facebook's? I understand that this combination of Notification + Subscription modules can accomplish a lot of different notification setups. However, I am only looking to emulate the notification system similar to Facebook, as in this example:

Can anyone provide any tip or guidance as to how this combination may be configured to achieve this goal?

Any sugestions?

you can use my module for this Total Subscription.

  Total Subscription provides functionality which would allow the user to subscribe to node pages, taxonomy terms, etc. The main feature which distinguishes it from other subscription modules is that it allows subscription for Anonymous along with Authenticated users.


Get Plugin Definition methods using dependency injection It is my first time defining a custom Plugin Type.
I think that this might be a comming thing in Drupal but I was not able to find any documentation anywhere.

I want to get Plugin definition methods from controller.

I use this code to get plugin definitions:

$type = \Drupal::service('plugin.manager.task');
$plugin_definitions = $type->getDefinitions();

And that gives me an array of all definitions with Plugin id, class and name.

What I want is to get methods from the definition class.

I don't know if I should create a service for every Plugin definition, but that doesn't seem to be a good idea.

Does Drupal Core have any tools to do this?

Hope that you understand.

Create an instance and then use a method on the plugin instance, for example to execute the task, if you have such a method in the plugin class:

$task = \Drupal::service('plugin.manager.task')->createInstance('my_task');

$task->execute();


How to make a clone of a website without contents I need to create a clone of one of my website.
It will be the same (modules, views, content types, template etc...)
I've already done once by coping everything and then deleting the contents and the users.
Is there the right way? I will need to do 3-4 copies of the website.
Is there any module that can help me(a part from backup and migrate) to do these copies? Should I create an kind of "distribution" enabling modules and creating content type, similar to the master one, from the scratch and then export the database?

If I do as I always did (clone and delete contents and users), how can I reset the content id?

Thanks in advance

I guess what your looking for is the features module http://drupal.org/project/features. When creating clones of websites, obviously all the code/themes/modules is easy to copy but the only way to get all your node types, fields, views etc... is in the database.

Features exports all this information as a module as you can just copy this to a new site along with all your other modules, enable it, and voila all your views content types etc..
In the features you can list modules as dependencies so when enabling your feature all the contrib/core modules you need are enabled aswell (they will ofcourse need to exist on your new area).

It intergrates fully with most the big contrib modules and from what I understand is exactly what your after. It can be daunting at first but dont worry its really very easy to use. The following video is for drupal 6 but the features interface is identical (as far as I remember) http://mustardseedmedia.com/podcast/episode43

There are other more complex ways to do what your after aswell using drush and creating build scripts, you can ever combine drush, build scripts and features. However I believe just normal features will do you fine.


enable Rule module with fatal error I use drupal 7.26 and try to install Rules(7.x-2.6) with drush (drush en rules -y)

I can not visit my drupal site Now.

I install Xdebug. this follow is error detail:

Fatal error: Class name must be a valid object or a string in /Users/tangmonk/MyGit/Drupal/daxuebao/includes/common.inc on line 7837

#   Time    Memory  Function    Location
1   0.0011  240392  {main}( )   ../index.php:0
2   0.0155  656312  drupal_bootstrap( ) ../index.php:22
3   0.2055  5039280 _drupal_bootstrap_full( )   ../bootstrap.inc:2260
4   0.6304  21000048    module_invoke_all( )    ../common.inc:5158
5   0.6328  21061544    call_user_func_array ( )    ../module.inc:895
6   0.6328  21061744    rules_init( )   ../module.inc:895
7   0.6343  21098688    rules_invoke_event( )   ../rules.module:12
8   0.6343  21099144    rules_get_cache( )  ../rules.module:969
9   0.6666  22764416    RulesEventSet::rebuildEventCache( ) ../rules.module:333
10  0.7564  25670784    rules_config_load_multiple( )   ../rules.plugins.inc:764
11  0.7564  25670872    entity_load_multiple_by_name( ) ../rules.module:804
12  0.7564  25670936    entity_load( )  ../entity.module:252
13  0.7564  25671016    entity_get_controller( )    ../common.inc:7804

Try going to http://yoursite.com/update.php and execute the form submit.

If this does not work, you must:

disable rules by SQL command:

UPDATE system SET status = 0 WHERE system.name = 'rules';
Execute drush cc all
Active drush again:

Drush en rules -y


Image Styles Not Generating Thumbnails/Previews I have File Browser installed on my website.  The module info can be found here:
https://www.drupal.org/project/file_browser

When I go to browse for pictures, there are no images. You can see what I see below:

Below, you can see "WHY" it is not loading.

It seems to think that the system should have generated thumbnails and it is trying to reference those thumbnails.  However, the files have not been created.

/sites/default/files/styles/file_entity_browser_thumbnail/public/md-slider-image/slide-corporate-3.jpg?itok=O25-iC4D

My next thought was that maybe the GD manipulation tool was not enabled and the system needed that to generate the thumbnails.  I checked using command line and that program is installed.

GD Support => enabled
GD headers Version => 2.2.4
GD library Version > => 2.2.4

After further review, I went ahead and discovered that the "image style" functionality of Drupal is what is supposed to be generating the images. So, I went and just tried to use the "normal" image style functionality by adding an image field to a node and attempting to apply a style in "display settings."  When I did this, it did not work.  So, it seems the issue lies with "Image styles."

The most obvious solution would seem to be that I do not have the permissions set correctly.

I went to /sites/default/files/ and the owner is www-data (apache) and the "octal" is 0777. I also made sure to apply these permissions "recursively" so it would copy down to any sub directories.  Nothing seemed to change after doing that.  I also am not getting any errors that I can find.

Does anyone have any suggestions on how to fix or where an error might be generated that could point me in the right direction?

The solution for the image style issue was to alter the HTACCESS in that folder so it would allow apache to use image files.

I can also confirm that it WILL NOT work if you do not have your apache rewrite module turned on.

Final note - this will work without the octal being "777" as I mentioned in original post.


How can I get additional fields from Search API query? I have Search API DB backend where I will be retrieving thousands of results and I need some fields to get out of there as well, beside search item id, since doing additional query to MySQL with IN condition consisting of thousands of entries is nonsense.

Can't find any methods to do this in the code so far though.

I think the query option search_api_retrieved_properties is the key, but I was not able to make it work yet.

I have added the fields via hook_search_api_db_query_alter on tagged query but they are not present. Calling getField() on the result item always queries the source entity(= entity_load operation).

Unfortunately, it looks like this is impossible.

Looking at \Drupal\search_api_db\Plugin\search_api\backend\Database::search:

  $result = $db_query->execute();

  foreach ($result as $row) {
    $item = $this->getFieldsHelper()->createItem($index, $row->item_id);
    $item->setScore($row->score / self::SCORE_MULTIPLIER);
    $results->addResultItem($item);
  }

The $item will receive only the item_id from the fetched row, so all added fields are lost :(


Showing total of amount in view I am listing the fee of students in a view developed using views 3. How can I show the total of fee for all records displayed at bottom as Total Fee:

Thanks for your help.

Sounds like a job for Views Calc.

  This module adds simple calculations to a views table. Requires the
  Views module.

  You can SUM, AVERAGE, COUNT, MIN, MAX, or AVG selected columns. A plug
  in theme makes the view look more spreadsheet-like (right justifies
  numeric fields, shades calculated columns and rows, and underlines
  calculated rows).


Receiving http status code 406 I have created a custom module in Drupal 8 and added the routing table to mymodule.routing.yml. Whenever I am trying to hit a particular path, I am receiving the HTTP response "406 (406 Not Acceptable)."

What is causing this?

You need to return a Response object or a render array from a controller.


How to track field changes in custom (ECK) entities I'm using Feeds to import an online spreadsheet into Drupal (ECK) entities.
This goes okay but there doesn't seem to be a module (?) that allows to view the tracked changes in the entity fields.
There is one module that is promising but doesn't yet support custom entities: "Track Field Changes"https://www.drupal.org/project/track_field_changes

So the question is: is there an alternative module or way to view changes of entities, especially the field changes?

I tried the diff module but that doesn't give an overview of entities that have changed?

You can try ECK Revision module. Also check related drupal.org issue: Support Revisions in ECK.


Unclickable Menu link keeps refreshing my page Hello and sorry for my bad English. I am using Drupal 8 and i want to make a menu with categories. The menu title has to be CATEGORIES and when someone click on it, the menu has to show the categories with a drop down. So i've created categories. Then i created a menu called - CATEGORIES and i marked "show as expanded". In the menu link i added - "route:<nolink>" . So now i have Categories menu with drop down listing categories, but when i click on it, the page is refreshed. I dont whant the page to be refreshed everytime i click on CATEGORIES. I just want to show me the drop down and not refreshing the page... I am using this theme https://www.drupal.org/project/news_zymphonies_theme and if you click on Live demo you can see in main navigation the menu link - "LAYOUT". When you click on it, the menu shows 2 categories - "two sidebar" and "left , right". In my case when i click on LAYOUT will show me this two categories but it will refresh the page too and i dont want to refresh it. How to fix that? Please help me i've readed so many topics and didn't find a solution :(

Ok, i've solved the problem for now. I've just typed ## in "CATEGORIES" link instead of one #. Now when i click on CATEGORIES, the page is not refreshing and a drop down menu appears.


where is the submit handler for the Drupal Commerce Review page? I need to know how the drupal Commerce review page is being created and where the submit handler is which precedes that page. I have added a couple of fields which aren't being picked up in the panes, and I want to debug in the handler (or even a review page tpl file). Where can I find this? I have looking though the code and havn't found the answer.

All checkout page forms are built using the checkout pane info David Thomas indicated through the function commerce_checkout_form() in commerce_checkout.pages.inc. The validate handler does double duty for the checkout form, validating and actually submitting data on a pane by pane basis to capture valid data as soon as possible. This function is aptly named commerce_checkout_form_validate(). Your best bet will be to log debug messages using watchdog instead of displaying them on the screen via drupal_set_message(), because we do some status message processing in there to put messages inline with the panes that generated them - that can make it hard to force a debug message to show when you expect it.


Rewrite URL not working In Drupal 6 I used the following snippet of code in my .htaccess file to extract information from a non-existent URL and pass it to an existing URL in a GET form. However, it isn't rewriting the URL with my Drupal 7 installation and when I visit a URL the should be rewritten, I just get a Page Not Found error! I have cleared all caches and even tried different browsers:

# Custom Rewrite  ScriptOptions +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^home/code/([^/]+) home/software?code=$1 [L,NC,QSA]

I have placed the code just after the default handler is set.

Could anyone tell me why this code isn't working? Should I be doing this a different way in Drupal 7?

UPDATE: Please see the question I asked on Stackoverflow to get this code working with Drupal 6 - https://stackoverflow.com/questions/10765799/rewrite-a-url-to-include-get-data-with-drupal

Handling of "Clean URLs" has changed from Drupal 6 to Drupal 7 in a way that affects Apache RewriteRule.

I'm not sure if that is what has bitten you since I don't recognise home/software?code=$1 as a typical Drupal URL. But I've found that in Drupal 7 I need to rewrite to a "unclean" URL.

For instance, the following will work in Drupal 6, but not in Drupal 7:

RewriteRule ^home/code/([^/]+) home/software/node?code=$1

In Drupal 7 you must not rewrite to a clean URL destination, even if you have clean URLs enabled.  The following will work in Drupal 7:

RewriteRule ^home/code/([^/]+) ?q=home/software/node/&code=$1


How to change the text in the revision log message? I would like to change the bottom text, "Provide an explanation of the changes you are making. This will help other authors understand your motivations.", in the revision log message section.  See attached screenshot.

How should I go about changing the text?

Use the following code in a custom module or in your theme's template.php:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function YOURMODULE_form_CONTENTTYPE_node_form_alter(&$form, &$form_state, $form_id) {
  $form['revision_information']['log']['#description'] = t('Your new instructions.');
}

Note: replace YOURMODULE with your module/theme name and CONTENTTYPE with machine name of the content type you want to change.


setting the url to a function in a custom module I am trying to make a link in a view which, when clicked on, will call a function in a custom module to make a database call. I have made a link by making a Global:custom text field (because thats the way it seemed I had to do it from some posts online), set it to a path accompanied with some arguments. I made a custom module used the hook_menu:

function example_menu() {
$items = array();
$items['path_name'] = array(
'title' => t('Example'),
'page callback' => 'my_callback',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}

where function my_callback does a database call.

When I click on the link I just get a blank page with nothing on it. Which pieces am I missing here? The first thing I thought was that I needed to route the link to a page (hence the name 'page_callback') but how would I do this? All I really want done is a database call, I don't mind if you stay on the same page.

EDIT:
Additionally, what I have found is that on the content management page there ares some errors on top which tell me that I'm missing arguments 1 through 4 (there were four arguments), which definitly can be part of the problem. The function starts off:

function example_my_callback($staff_action, $first_name, $last_name, $email)

and the url for the link was path_name?staff_action=[varible name found in views]...etc
Is there any issue here?

The page callback must be the name of the function that will return the data from database

You must create a function like this :

function my_callback(){
// here you will connect and pull up data from the database
return $your_data;
}

Also don't forget to clear the cache and read about the database API here


Not administrator - manage users I have a user "manager". This user has the manager role but not the administrative role. Is it possible to allow this user to manage users and their roles? For example, if someone creates an account I want this user to be able to activate the account like an administrator can? And then to give a role to that user?

Or even change roles of existing user?

I have searched. But no luck.

Thanks in advance :)

Don't understand why Kevin's answer hasn't been accepted yet, here you go with a snip of the permissions that need to be enabled.

Have a look at this module- Administer Users by Role
These are the new permissions that come with the module -

NEW PERMISSIONS
1 )Access the users overview page
  See the list of users at admin/people.  Only users that can be edited are shown.

2) Create new users
  Create users, at admin/people/create.

3) Edit users with no custom roles
  Allows editing of any authenticated user that has no custom roles set.

4) Edit users with role XXX
  Allows editing of any authenticated user with the specified role.
  To edit a user with multiple roles, the sub-admin must have permission to
  edit ALL of those roles.  ("Edit users with no custom roles" is NOT needed.)

-The permission for cancel work exactly the same as those for edit.


how to add a terms to a vocabulary by form? I'm using drupal 7
I need to create a form that can add new terms to specific vocabulary.
Which function can do that?
Thanks

Check this link taxonomy_term_save($term)


What's the best way to add an entity (of a specific type) selector to a form? I can achieve what I want by using the EntityFieldQuery and transforming it to be the right format for a radio options array.
Is there a better way?

If you're operating on an entity, you can just use an Entityreference field which will do it for you.

If not, then yes, write it yourself and use EntityFieldQuery. Just watch out, entityCondition('bundle') is broken for comments and taxonomy terms, and entity access is non-existent (so it will show all users instead of the non-blocked ones, etc).
Entityreference implements workarounds for this (until it gets fixed in core), so you can take a look and borrow that code if needed.


Simulating Facebook videos embedding behaviors in Drupal? If users are posting comments to a Drupal site and the comment contains a link to a video on YouTube or other sites, I would like to see similar behavior to that when posting a link to a video on Facebook. That is, once the link is entered, it triggers the embedding mechanism and generates a preview in edit mode.

The emfield module does that. It's D6 only at the moment.


Media name as link to file I have a "Document" media bundle, and I have a custom view mode called "Embed".

In that view mode, I have removed everything except the media name property and my document file field.

For media name the only format available is plain text, with an option to "Link to Media". This provides a link like media/2, where you can click on a link to download the file.

For my document field, I get Generic file (the file name with a link to it), RSS enclosure, Table of files, and URL to file.

Does anyone have a simple way to generate a link like Generic file but show the media name instead of the file name? e.g. Handbook vs handbook__2017_fin_updated_some_other_rubish_26.pdf

This is not possible with just the formatter configuration, someone would need to create a "Link to file with entity label" formatter, which would also not be that complicated.

But you can do it quite easily directly in a media template, the name would be something like media--document--embed.html.twig and the content then looks like this:

  {{ name }}

I also included a target and noopener rel here, but that's of course up to you.


Create node before page load I have a web service on third party system that return property of doctor and I have a content type named "doctor".
I want when user go to a url like doctor/23 drupal create a node of type doctor based on url arg and show this node to user.
for that and with @zaporylie help i create a custom controller like bellow

create a Routing:

    showdoctor.load_doctor_controller_load:
  path: 'doctor/{doctor_id}'
  defaults:
    _controller: '\Drupal\showdoctor\Controller\LoadDoctorController::load'
    _title: 'load'
  requirements:
    _permission: 'access content'

and my controller like this:

    class LoadDoctorController extends ControllerBase
{
    public function load($doctor_id)
    {
        $result = RestCurl::post("http://myrest_server.com", [
            'filter' => ['doctor.id' => $doctor_id],
        ]);

        $fullname = $result['data']->message->data[0]->firstName;
        $fullname = $fullname . ' ' . $result['data']->message->data[0]->lastName;
        // Fetch doctor node with EFQ
        $query = \Drupal::entityQuery('node');
        $query->condition('type', 'doctor');
        $query->condition('field_doctor_id', $doctor_id);
        $nids = $query->execute();
        if (!$nids) {
            $node = Node::create([
                'type' => 'doctor',
                'title' => $fullname,
                'uid' => 1,
            ]);
            $node->set('field_doctor_id', $doctor_id);
            $node->save();
            $element = array(
                '#markup' => $node,
            );
            return $element;
        } else {
            $element = array(
                '#markup' => $node,
            );
            return $element;
        }
    }

}

Now for example when in go to doctor/23 page i see a page with load title. and if i refresh this page i see doctor page correctly. i think my problem is return value.

You should create a custom Controller rather than hook on page load. This way you won't have an overhead on every page load. In the Controller (accessible under movie/{movie_id} route) try to load movie by movie_id (entityQuery), and if it does not exists simply create one based on data from 3rd party service and display in a display mode of your choice.


How to allow the setting of the Views Exposed Filters one at a time, instead of showing all available exposed filters at once I have a view with a ton of exposed filters. Placing all in one page (even in a collapsible fieldset) is overwhelming for the users. Is there a module that allows a users to add a filter one-by-one?

Hopefully the screenshot of a third party application helps to explain

I believe the views dependent filters module will do it for you.

I haven't used it but from what I can see it works just like dependent fields.


Database corrupted getting the site crash I crashed my website trying to secure it by changing files and folders modifications...After i tried many things (chmod 777 -temporarly- all to take it back, clear the cache, drush rr...) nothing worked yet. So i tried to install a new site, copied all the site file...It was working perfectly.

I tried to link the new site with my old database, and the fatal error get back again...I guess my database might be corrupted...Any idea ?

Thanks for your help

(previous conversation about what i did already here

As webdrips has said, your error seems to be with the xmlsitemap module, and considering it is not critical for functionality, you should try disabling it.

Depending on the state of the website, if you are experiencing WSOD, you may need to disable the module through the database using phpmyadmin.

In the system table, find the xmlsitemap module, and edit the row where the column is "status", and set that to 0.


Can I use the Search API module and its facets without a server running Java? The host I am currently using doesn't support Tomcat or Java applications of any kind.
Is there a non-Java based search server, or are my only options a third-party host or migrating to a new host?

Try to use search_api_db it support facets and some other features.


HOWTO: Common fields (weak entity) Long story short:

I have various entity types in my system and some of their subsets (bundles) has the very same fields. So far I have 3 "common fields" sets, which are from EntityRelation perspective the weak entities. A set has from 3 to 9 fields in it.

The following constraints I need:

When changing something in field bundle settings (eg: make it
required) I don't want to sync all of the other occurrence
of this    field.
Field content should be translatable (based on the
    parent)
Field content should be revisionable (based on the
        parent)

So far the following solutions came to my mind:

Field Collection (bad experiences in D7, still in dev)
Separate bundle / entity (ECK maybe) + Inline Entity Form (months ago
there was a problem with revisions)
Paragraphs (translation + revisioning good, but I couldn't make it to
appear in forms just like Inline Entity Form (it always had the "+
Add new paragraph" and if it was a new content, the form of the
paragraph didn't appear, only after clicking the add button)
Custom entity, which includes these fields as base fields. (a lot of hassle to generate the forms, listers, revision support.. etc.)

Do you have any advice for me to solve this issue?

Not a defintive answer, just some input.

We (the paragraphs maintainers) are working on reaching feature and user experience parity (or be better, of course) with the Field Collection module, specifically for non-typical paragraph scenarios (single paragraph type, single cardinality, default paragrapht type, ..). There are discussions on officially deprecating field collections in favor of Paragraphs, this might or might not happen. So I'd recommend to not use FC, but I'm obviously biased there.

The latest Paragraphs dev version has support for setting a default paragraph type now, which means that it will by default show the form fields for that already, and you don't need to add a type. The add button should only be shown if you allow more than one field, which is the default for paragraph fields but can easily be changed.

Revisions should work fine in IEF as well, if you use an Entity Reference Revisions Field. If not, then you'll have to report a but, but I assume the maintainers are actively working on that as it is a critical element of Commerce 2.x.

One important difference between the two is Paragraphs are by definition a composite of the parent node, that means they have a parent reference and not re-usable, in case that is a requirement. IEF doesn't have that and allows to search and reference existing entities.

The advantage of custom entitiy types (with base classes or traits to re-use base field definitions) is that they're way more efficient, Paragraphs/IEF both result in separate entities that need to be saved, and all the configurable fields need to be stored in separate tables. With custom entity types, you can add all the fields you need as base fields. We're constantly working on requiring less code for custom entities, listings can be done with views with none or very little custom code, widgets work for base fields too, so anything you can do with configurable fields can be done with base fields as well. One major pain point right now is a revision UI, but we're making improvings there as well and entity.module provides some basic user interfaces there as well, diff.module is also working on supporting all entity types.

Yet another option would be to define base fields/configurable fields in code. That is possible as well, but I personally wouldn't really recommend it, there are still some unfinished areas there, especially uninstalling/removing those fields is really hard, as the delete/purge process only works for configurable fields. You could technically also maintain configurable fields with code and sync them between multiple bundles.


Allow a user to select where to save an uploaded file I have installed an Open Atrium, which is based on Drupal 6, but this is a rather general question towards Drupal 6.

In every content type I have an Upload File field which work just fine, but it does not quite meet my requirements.
I have already defined an directory structure on my server, which I would like to maintain as is. Therefore, the functionality I am trying to achieve is to allow a user, who selects a file to upload from local computer, to be able to select the path where to store it (preferably outside of Drupal installation).

To be able to reach an outside directory I have created an alias to the necessary directory (e.g. C:\blalbla\  --> localhost/dev).

You could use a text input with select list, allowed values list will be generated with php code reading the directory you created, then using File (Field) Paths you will save the upload on the select list input.


Where is the base domain stored in database D7 Is there an equivalent row to the Wordpress "Home" and "Site"? In otherwords, where can I look in the database to figure out what the domain the site is on?
 I'm using mysql

I think you're looking for $base_url in /sites/default/settings.php.  As far as I know everything in the database works off this value, and it is not explicitly set in the DB


How do print term image field as background style attribute in views-view.tpl.php? How do print term image field as background style attribute in views-view.tpl.php or in views-view-unformatted.tpl.php file?
I have view which lists terms of taxonomy vocabulary. All terms have title and image fields. I need to lists terms like:

Title

Title

You can achieve this with row style instead. Go to your views advance settings then click on theming information and look for appropriate name for row styling and write something like this.

$uriImagefromView = $row->field_field_image[0]['rendered']['#item']['uri'];
$urlImagefromView = file_create_url($uriImagefromView);

This will give you the url to the path of that image. Now you can easily render it as background.

If you want to render your background image in particular size you created in image style you can do like this

$resized_url = image_style_url('<style_name>', $uriImagefromView);


How to change the image size within a Drupal view Does anybody know the best way to change the image size of a field within a view using Drupal 8?

You can create an image style at admin interface and then use same style at your view settings.

Navigate to admin/config/media/image-styles and add new style. After that edit image field inside your view which will look like below image.

In image you can see Image style which you have created in earlier step. This way you can change the image sige at views.


How to identify disabled fields in form submit handler? I have a pretty complex form, on which fields are getting enabled and disabled conditionally. I'm using JavaScript to do that without call to server for performance purposes.

How can I not save values from fields that are disabled? Some of the conditions are not entirely based on field values, but also on user's behavior on a form, so it is not possible to simply recreate logic in PHP.

Currently I'm emptying disabled fields before submit, and then testing if $form_state['values']['field'] is filled and $form_state['input']['field'] is empty. If so, I assume field also got disabled, as my script does not allow to submit empty enabled fields. This gives me workable approximation of what I need, but prevents me from implementing graceful degradation for no-js clients, so I need a better solution.

There's not really enough information in the question to provide a definitive answer but what I'd suggest is:

add one or more hidden fields to the form to hold state information
store values in the field(s) using javascript when the state of the form changes with user action
On the server side, use the value(s) from the hidden field(s) to represent the state of the form so you can employ them in validation logic.


Alter field collection edit form in hook_menu_alter I need to create my own form and validation (when field collection entity is Edited).

function common_menu_alter(&$items) {
    //alter add(insert) - working
    $items['field-collection/field-block-id/add/%/%']['page callback'] = '_common_field_collection_item_add';
    //alter edit - not working
    $items['field-collection/field-block-id/%field_collection_item/edit ']['page arguments'] = '_common_field_collection_item_form'
}

_common_field_collection_item_add() is my own function in my common.module.

I managed to alter the entity on insert, but changing the "edit" part doesn't work. This is the path of my field collection edit: field-collection/field-block-id/%/edit?destination=node/%.
I tried to put this path to $items, but it still doesn't not work.

In hook_form_alter() I did this.

if ($form_id == 'field_collection_item_form' && arg(3) == 'edit') {
       $form['#validate'][] = '_common_field_collection_item_form_validate';
       $form['#submit'][] = '_common_field_collection_item_form_submit';
}

Better to use the Field Attach API hooks instead.

e.g:

hook_field_attach_form
hook_field_attach_validate


How to handle complex test results? Actually we are using D7 mostly for books and book pages like manuals.

We would like to link files like PDF and Excel to a Drupal book page but we have no experience how to manage to open those files from drupal or view their content in drupal.

Therefore I would appreciate instructions for eventually necessary modules and settings.

We have a browser extension in chrome for PDF and see them directly in the browser , but from a Drupal page (localhost:8080/drupal/?q=it/node/398), the link to that PDF first gets me to another page (drupal/?q=media/1242`) and I have to click again on the PDF icon to open it in the browser. Thaty's somewhat annoying.
Can anyone please indicate a direct way for PDF and for Excel files? Is it necessary to fit the browser for Excel? if yes, how?

Instead of "... save the differences in an Excel table ...", you might want to consider saving these data in an external database (MS SQL, MySql, Oracle, some PDO compliant database, etc).

And then use the Forena module to build custom queries to retrieve the data (directly from such database) and create custom reports from them. Those reports can then be exported in PDF or Excel. For that you just have to enable the desired Forena report options called "document format".

Refer to my answer to "How to download Database results as PDF or in EXCEL" for more details.


Building the sidebar content on each node Im going to build a version content heavy site that will contain over 100 of pages. All pages are created in a "Two column layout" the main column contains the Title and body text of the node. And then theres the sidebar, i like the admin of the site to be able to "build" the sidebar for each node.

I like to provide the admin with two types of elements a "text box" and a "image with text box". The admin should then be able to create any number of each box in the sidebar, and they just get listed under each other. These boxes should be attached to the node, and is not general for all nodes.

Basicly im hoping for a solution where they can setup the node, when they visit the node they could hover over the "sidebar" region and in the dropdown select "add textbox" -> "add image box" and those teasers get assigned only to the specific node

It should be very intuitive as the admin is not very techinical (for example they wont be able to create views etc) so im hoping for a simple solution, please advice me :)

There probably is a better solution, but this is what I thought of.

Make two new content type of 'sidebar-block-text' and 'sidebar-block-image'. And in those content types add a node (or entity) reference field. (Make sure to use the same field, so create it once, and for the other content type choose it from existing fields!)
Build a view-block.

Let it display the whole rendered node.
Add a contextual filter of the current node id and link it to the reference field.

Place the block in the template sidebar region.

All the administrator will have to do is to add a new piece of content (sidebar-block-text or -image) and reference it to the 'parent node'.


How to reference existing entity using Inline Entity Form? I'm using Entity Reference to create tasks in lists - both tasks and lists are content type, list contains multivalue Entity Reference to task. Because most tasks belong to only one list, it was only natural to use Inline Entity Form.

Problem is most - there are some tasks that needs to belong to many lists.

Module's docs says:

  Existing entities can also be referenced.

That would do the trick. My question is very simple: How do I do that? Only button I see is "Add new node", and it opens node creation form. What should I do to see "Add existing node"?

To add more clarity to the answer:

In Edit tab, check "allow users to select existing nodes"
as shown below

In your content creation form, you could find two buttons: Add New Node and Add Existing Node  as shown below


Restws authentication How can I login to my Drupal in API way and use the rest ws module with API calls?

For example, I have a user with name test. I want to login with test user then use API calls with something like a token or identity (I don't know what) and make Drupal recognize user in :

global $user;

How is it possible?

I tried to post username and password to /user/login path  and get token from /restws/session/token

It returns something like this :

emGevPKZl9aLe90tOJ1ZK9rnp--6BMeNV3RP27aqcsY

but when I use it in header parameters with name X-CSRF-Token it does nothing.

You would probably have an easier time using the services module it's better supported and used far more than the restws module. It supports several types of web service calls including RESTful.

SERVICES:

  A standardized solution of integrating external applications with Drupal. Service callbacks may be used with multiple interfaces like REST, XMLRPC, JSON, JSON-RPC, SOAP, AMF, etc. This allows a Drupal site to provide web services via multiple interfaces while using the same callback code.


Admin -> Run Updates, Unresolved dependency When I click Run Updates from admin, I got som Unresolved dependency errors.  It told me File Entity (Version >7.x-2.0 required), but I'm using 2.0-beta3, as the next line stated.

file_entity.info is found in sites/all/modules/file_entity/file_entity.info

So what am I missing?

So what am I missing?

Nothing at all, the messages are pretty clear:

The version of CKEditor Media Browser that you're updating to has a dependency on File Entity 7.x-2.0 or greater. You have version 7.x-2.0-beta3, which is not greater than 7.x-2.0, so the upgrade isn't possible.

You need to update File Entity to the required version first, then proceed with the update of the media browser module.

Do bear in mind that the modules you're dealing with are in beta, and haven't had development effort in a while. It's entirely possible that you might not be able to perform the update. Case in point: https://www.drupal.org/node/2838674


How to get Panels to pass a correct date to Views (D7, Views/Panels3) I'm trying to get a date from a node to a view pane. When someone is viewing the node, they should see a view on the right that is just a list of other nodes with the same day in the "event_date_time" field.

Here's screenshots of how everything is set up:
http://imgur.com/a/eXCMA

1) First is the pane layout. The left is the node content with event_date_time. The right top is a view panel that has no filters, so you can see all the nodes and dates. Below it is the same view panel with a contextual filter.

2) the current results. You can see the right bottom only matches the two nodes that have the exact same year, month, day, hour and minutes.

3) the contextual filter setup. It's set with granularity of days, but doesn't seem to make any difference what granularity is set. Even if it is changed to "year", it still only returns the one exact matching item. If I change one of the two matching nodes from 4:00 to 4:15, they no longer match.

4) I'm asking for the date field from the Panel context in Views

5) And it's set up in Panels to send

6) The contextual filter returns the correct 4 events that match the day, if I manually pass it a YYYY-MM-DD format.

I looked through the context and relationship options in both panels and views and can't see any other way to send or format this date. I feel like I must be missing something basic in my understanding of how this is supposed to work.

(I get the same results whether I create the contextual filter using "Content: Event Date Time" or "Date: Date (node)", and whether they are set to "date range" or "only this field".)

This is Drupal 7.22, Panels & Views both current dev.

After struggling for some time, I've still not found any way that works via context from Panels. Other people have said Panels values were determined by the "token" content display mode, but that isn't the case, at least with dates. Of course you can put the value in the URL and have Views grab it there, but for my use that wasn't appropriate. It also seems more fragile since it makes all content dependent on the path structure.

The best option I found was setting the "Argument Input" on the View to "Input on Pane Config". Then in the Panel Pane, use keyword/token substitution. I created a custom date & time formatter that is CCYY-MM-DD, called "date only", and set the Panel option to "%node:field-my-date-field:value:date_only". That grabs just the first value from a date range. For a field without range, "%node:field-my-date-field:date_only" works.


Views performance issue I have a website with 4 views (and sometimes 5 views) on the homepage. The problem is that when I try to open the website, it takes minutes to load and the cpu goes crazy because of mysql processes.

Screenshot of cpu usage

Output of SHOW PROCESS LIST

I work on a dedicated server with 8GB of RAM, 1900Mhz Intel Hexa-Core Xeon and 4 × 300GB SAS (RAID 10)

I have been using drupal for years, and never encountered such an issue. Any ideas how to fix this?

Update Views query:

SELECT DISTINCT node.title AS node_title, node.nid AS nid, node.language AS node_language, node.created AS node_created, users_node.picture AS users_node_picture, users_node.uid AS users_node_uid, users_node.name AS users_node_name, users_node.mail AS users_node_mail, taxonomy_term_data_node.tid AS taxonomy_term_data_node_tid, taxonomy_term_data_taxonomy_term_hierarchy.tid AS taxonomy_term_data_taxonomy_term_hierarchy_tid, 'node' AS field_data_field_news_photo_node_entity_type, 'node' AS field_data_field_op_section_term_node_entity_type, 'node' AS field_data_body_node_entity_type, 'user' AS field_data_field_user_realname_user_entity_type, 'user' AS field_data_field_user_organization_user_entity_type, 'user' AS field_data_field_profile_picture_user_entity_type
FROM
{node} node
LEFT JOIN {users} users_node ON node.uid = users_node.uid
LEFT JOIN (SELECT td.*, tn.nid AS nid
FROM
{taxonomy_term_data} td
LEFT JOIN {taxonomy_vocabulary} tv ON td.vid = tv.vid
LEFT JOIN {taxonomy_index} tn ON tn.tid = td.tid
WHERE  (tv.machine_name IN  ('sections')) ) taxonomy_term_data_node ON node.nid = taxonomy_term_data_node.nid
LEFT JOIN {taxonomy_term_hierarchy} taxonomy_term_data_node__taxonomy_term_hierarchy ON taxonomy_term_data_node.tid = taxonomy_term_data_node__taxonomy_term_hierarchy.tid
LEFT JOIN {taxonomy_term_data} taxonomy_term_data_taxonomy_term_hierarchy ON taxonomy_term_data_node__taxonomy_term_hierarchy.parent = taxonomy_term_data_taxonomy_term_hierarchy.tid
LEFT JOIN {field_data_field_news_photo} field_data_field_news_photo ON node.nid = field_data_field_news_photo.entity_id AND (field_data_field_news_photo.entity_type = 'node' AND field_data_field_news_photo.deleted = '0')
WHERE (( (node.status = '1') AND (node.type IN  ('news')) AND (field_data_field_news_photo.field_news_photo_fid IS NOT NULL ) AND (node.language IN  ('***CURRENT_LANGUAGE***')) ))
ORDER BY node_created DESC
LIMIT 12 OFFSET 0

EXPLAIN output.

The process list is saying that Mysql is writing to tmp tables.  The issue is the way you configured mysql.  Check the my.cnf configuration, and make sure that the temporary tables are large enough.


Use webform submission id in custom content type I am working on a patient/doctor kind of project where by the patient fills a questionnaire and then the doctor provides a prescription.

I have used webform module to create the questionnaire which the patients would fill, and i have created a custom content type for the prescription.

I need to be able to relate the submission Id of the questionnaire to the prescription but I am not sure how to do it.

Please note that a patient can fill various questionnaires so it is quite important that I use the submission id as it seem as the only unique id available.

I have tried the node reference module but that only gives me access to the questionnaire not submission id of the questionnaire.

You're right - you can't use references with the webform submissions, because webform submissions are stored in their own special way - they're not actually proper Drupal entities, so they are not properly exposed to other modules expecting to interact with entities.

One thing you can try if you're not too far along in your project is to use the alternative Entityform project.  That should expose form submissions to be referenced.

Let us know if it works!  I haven't used the module myself, I've just heard of it.


How to customize the user login form? I'm trying to customize user login form in /user/login page and I want to use a hook_form_alter function to add some awesome style and placeholder to each of user login form fields and remove or hide: "Enter your admin username" and "Enter the password that accompanies your username" description expressions under each of theme.
To resolve this issue I added something like below code to my ThemeName.theme:

function ThemeName_form_alter(&$form, $form_state, $form_id) {
  if ( $form['#form_id'] == 'user_login_form' ) {
    $form['actions']['submit']['#attributes']['class'][] = 'button glow button-primary expanded';
    $form['keys']['#attributes']['placeholder']['name'] = t('User name');
    $form['keys']['#attributes']['placeholder']['password'] = t('Password');
  }
}

I try out many different ways but I can't get any result.
in finally I want to achieve something like below image:

I read this pages but seems none work in Drupal 8:
How to modify the fields of user registration form and user login form?
Modifying the default user registration page
Customize user login block

You can add placeholders in hook_form_alter().

/**
 * Implements hook_form_alter().
 * @param $form
 * @param \Drupal\Core\Form\FormStateInterface $form_state
 * @param $form_id
 */
function ThemeName_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if ($form_id == 'user_login_form' ) {
    // Add placeholders.
    $form['name']['#attributes']['placeholder'] = t('User name');
    $form['pass']['#attributes']['placeholder'] = t('Password');
  }
}

Use the Devel module functions to print out the form using kint, this way you can visibly see the entire structure of the $form array.


Displaying Grouped List Items Inline Hello i was hoping to create a list view that would look something like this-

FOOTBALL TEAM A
football team a link one - football team a link two - football team a link three

FOOTBALL TEAM B
football team b link one - football team b link two - football team b link three

etc etc

I have created a view and have it grouped by team. Everything works well. Its just the links below it are also vertical and not horizontal. You can view it here-
http://onlinebanter.com/football/links

Ive tried various bits of  display:inline aound the view but i just cant seem to find the place that works. Could anyone advise me please?

Thanks

You need to add css to your theme css file and clear cache to see the effect...

I am not a css guy, but below css code should work...

.view-footballlinks .item-list ul li {
  float:right;
}

Try, and let us know...