title: Why doesn't my custom library load?

text:
# Question
Title: Why doesn't my custom library load?
I am trying to load libraries in my Drupal 8 site, but it does not seem to be working. Here is my library yaml, is this correct? Why can't I load dexp.slides?

```
dexp.slides
  version: 1.x
  css:
    theme:
      css/plugins/font-awesome/css/font-awesome.min.css: {}
      css/admin.style.css: {}
      css/plugins/rs-plugin/css/settings.css: {}
  js:
    js/dexp.layerslider.js:  {}
    js/plugins/rs-plugin/js/jquery.themepunch.revolution.min.js:  {}
    js/plugins/rs-plugin/js/jquery.themepunch.tools.min.js:  {}
  dependencies:
    - core/jquery
    - core/jquery.ui.draggable
    - core/jquery.ui.dropable
    - core/jquery.ui.sortable
    - core/jquery.ui.dialog
    - core/jquery.ui.tab

```

I am trying the above way but the dependencies are not being loaded.

# Answer
> 1 votes
You are missing a colon after depx-slides:

```
dexp.slides:
  version: 1.x
  css:
    theme:
      css/plugins/font-awesome/css/font-awesome.min.css: {}
      css/admin.style.css: {}
      css/plugins/rs-plugin/css/settings.css: {}
  js:
    js/dexp.layerslider.js:  {}
    js/plugins/rs-plugin/js/jquery.themepunch.revolution.min.js:  {}
    js/plugins/rs-plugin/js/jquery.themepunch.tools.min.js:  {}
  dependencies:
    - core/jquery
    - core/jquery.ui.draggable
    - core/jquery.ui.dropable
    - core/jquery.ui.sortable
    - core/jquery.ui.dialog
    - core/jquery.ui.tab

```

The YAML is pretty strict about format. You can run it through a linter like YAML Lint \- that is how I noticed the colon was missing.

After making that change, clear your cache and require your library (either in the info file or by attaching it with #attached or attach\_library in a twig file) it should work.

The official docs page has all the info you need about attaching libraries, but the YAML must always be correctly formatted.

That YAML Lint tool, by the way, works for any YAML. If you ever work on a routing, permission or other YAML files, it can check if it is valid or not which is the first step to debugging YAML - simply eyeballing it is not good enough - use the tool that will just *tell you*. There is an npm package available to run it from command line (I do recommend).

---
Tags: 8
---


# Question
Title: Video Module: YouTube controls missing for one video but not the others?
Super strange issue: I've installed the Video drupal module, and it works great. However i've uploaded two separate videos, and for some reason, the YouTube controls disappear on this video:

http://truecallingcanada.com/video/seaspan-large-ship-welder

But not on this video (uploaded the same way):

http://truecallingcanada.com/video/not-for-the-faint-of-heart

Any idea as to why this module is removing controls from the former? If so, how can I fix this? I want controls on all uploads (and yes, the video embed settings are set to display controls).

# Answer
> 1 votes
The YT controls are there, but they're hidden behind the div.grey-bar element.

I'm seeing a difference between the two pages in this block:

```
<div class="content clearfix">
  <div class="field field-name-field-subtitle field-type-textfield-label-above">
    <div class="field-label">Subtitle: </div>
    <div class="field-items"><div class="field-item even">Chef and Restaurant Owner</div>
    </div>
  </div>
</div>

```

The page showing the controls has data in this field, making the div.content block taller (essentially pushing div.grey-bar down).

---
Tags: 7
---


title: Disable a default theme

text:
# Question
Title: Disable a default theme
I want to disable the default theme in my Drupal 7.5 system installation instance. How can I do this? I can't find a *Disable* link using the Creative Responsive theme version 7.x-1.1.

# Answer
> 3 votes
Drupal requires that one theme must always be set as default. Further, you cannot disable a theme that is currently set as default.

Best bet would be for you to enable another theme, set it as default, then disable the one you don't want.

# Answer
> 0 votes
Drupal will require at least one theme to be set as default. You will need to setup another theme as default and then you will be able to disable this theme.

---
Tags: theming
---


# Question
Title: How do I get the content of a Panel variant to display on as Content?
I've made a module that you can add to a Panel Variant's Content section by clicking a region's gear icon and selecting 'add content'. This seems to work fine and I can view the module's output if I set the Selection Rules to a certain url.

However, I want to add this module to a Node (by this I mean the sort of content where you can select Basic Page, Blog Post, Article, etc). When I click 'Add Content' I don't see where I can add the module - there's no Regions with little gear icons, unlike panel variants. It just seems like a page with a text field.

Would anyone know how I can actually add my Module to a new Content/Node page?

# Answer
OK I think I figured this out:

* 'Content' is actually Nodes. Don't know why they arnt just called 'Nodes'.
* There area different types on Nodes, these are called Content Types. You can add fields to a Content Type. Don't know why they're not called 'Node Types'.
* You can use Panel Variants as a kind of template for a Node. You can set Selection Rules to tell it which Nodes to apply it's self to.
* Here, in the Panel Variant you can attach Pane Component (my module) to a region.
> 0 votes

---
Tags: 7, nodes, theming
---


title: How should I call a form in a theme?

text:
# Question
Title: How should I call a form in a theme?
I read How do I find the search block form ID? several days ago. I want to use the answer given there in my project.

Where should I add this code in my project? Where can I find more information about it?

```
$form =\Drupal::service('class_resolver')-getInstanceFromDefinition('Drupal\mymodule\Form\Mymodule\SearchBlockForm');
$form->setFormIdentifier('some_custom_value');
return \Drupal::formBuilder()->getForm($form);

```

The key line of code here is this one:

```
$form->setFormIdentifier('some_custom_value');

```

Can you explain me what the code does?

# Answer
As per the comments from Jaypan, the first thing to do is extending SearchBlockForm so you can give it a custom ID. Put the code in mymodule/src/Form/MymoduleSearchBlockForm.php.
Add the following code in the custom class (in this case, `FoobarblkBlock`) to create a custom block. Put the code in mymodule/src/Plugin/Block/FoobarblkBlock.php

```
/**
 * @file
 */
namespace Drupal\mymodule\Plugin\Block;

use Drupal\Core\Block\BlockBase;

/**
 * Creates a 'Foobar' Block
 * @Block(
 * id = "block_foobarblk",
 * admin_label = @Translation("Foo Bar block"),
 * )
 */
class FoobarblkBlock extends BlockBase {

    /**
     * {@inheritdoc}
     */
    public function build() {
      $form = \Drupal::service('class_resolver')->getInstanceFromDefinition('Drupal\mymodule\Form\MymoduleSearchBlockForm');
$form->setFormIdentifier('some_custom_value');

return \Drupal::formBuilder()->getForm($form);
}

```

Place the block in the required region. The resulting form will be:

```
<form action="/search/node" method="get" id="search-block-form-some-custom-value" accept-charset="UTF-8">

```
> 1 votes

---
Tags: forms
---


title: Change the Default Empty Node Content

text:
# Question
Title: Change the Default Empty Node Content
I want to change the default empty node content of my Drupal site installation.

>

I want to customize its text display as well as the "Add new content" link. How can I achieve this?

# Answer
You can try this:

```
<?php
function THEMENAME_preprocess_page(&$vars, $hook) {
    unset($vars['page']['content']['system_main']['default_message']);
}
?>

```
> 1 votes

# Answer
Create a view with the content listet instead of using the default node page. That allows you to customize the "No results behaviour" with custom HTML.
> 1 votes

# Answer
You can use Empty Front Page module as well.

This ultra lightweight module modifies this behavior to show no default content on the frontpage. Only the blocks will be displayed.

More Options

Empty Page module.

Front Page module.
> 0 votes

---
Tags: theming
---


# Question
Title: How to display Poll results on most recent poll block
I'm using most recent poll block to display polling in fronend. After i closed the poll, result is not showing. So how can i display the pol result in most recent block. Please any one help me out to fix that.

# Answer
> 0 votes
Actually Poll module is making it to display only active poll as defined in these block

```
/**
 * Implements hook_block_info().
 */
function poll_block_info() {
  $blocks['recent']['info'] = t('Most recent poll');
  $blocks['recent']['properties']['administrative'] = TRUE;
  return $blocks;
}

/**
 * Implements hook_block_view().
 *
 * Generates a block containing the latest poll.
 */
function poll_block_view($delta = '') {
  if (user_access('access content')) {
    // Retrieve the latest poll.
    $select = db_select('node', 'n');
    $select->join('poll', 'p', 'p.nid = n.nid');
    $select->fields('n', array('nid'))
      ->condition('n.status', 1)
      ->condition('p.active', 1)
      ->orderBy('n.created', 'DESC')
      ->range(0, 1)
      ->addTag('node_access');

    $record = $select->execute()->fetchObject();
    if ($record) {
      $poll = node_load($record->nid);
      if ($poll->nid) {
        $poll = poll_block_latest_poll_view($poll);
        $block['subject'] = t('Poll');
        $block['content'] = $poll->content;
        return $block;
      }
    }
  }
}

```

As u can see this line in query -\>condition('p.active', 1) it is causing these issue if u want u can remove this line and check,

But hacking core is not the right way in drupal better implement ur own block use the same code and make changes and display your block. Just implement ur own block by using same code base.

---
Tags: blocks, polls
---


# Question
Title: How to approximate user location on IP&Geoloc maps
I'm using the combinaison of this modules :

I need to approximate the location of user's markers on the map for privacy reason.

For exemple if somebody live at *123 addressstreet 10000 Washington* I want the marker on leaflet map to point a random location in the area of this address and not the real geocoded location.

What's the best way to do that ?

# Answer
So, there's probably several ways to do this and your approach will depend on exactly what your needs are for this app.

If you need to preserve the geofield data accurately in the db, but you just want to change the display, you'd need to write a script to modify the Leaflet JS create.point function. This is complicated because you'll have to consider things like the visual context of what you're mapping (i.e. if there's only one house in an area, then even abstracting the location won't really accomplish what you want). Also, your changes will get wiped if your not careful upgrading modules potentially exposing the addresses your trying to hide (depending on how sensitive your data is, this may expose it as well, because someone might be able to dig through the JS and extract the original coordinates). This is also complicated, because simply randomizing the lat-lon data will produce really wonky map results (here's an alternate approach to randomizing user data. I would think that a good approach would be to choose a distance offset, and then randomly apply it to either the lat or lon value. This will keep your point close to where it should be, but it will be offset on either the X or the Y axis to the point where it shouldn't be on the exact location. You could also take the approach where you mis-match the real locations of the users to other users.

If you don't need to store the Lat-Lon accurately, you could write a custom module to hook into the geofield\_compute\_location function and apply your offset there. This will keep your addresses intact and then apply a similar function to the lat-lon values returned by whichever service is providing your geocoding. This will give you obscured location data to pull into your view.

There's also probably a way of modifying the geocoding request to only provide city-level accuracy, but this is getting over my head.

Hope this helps.
> 0 votes

---
Tags: 7, users, location, entities
---


title: Twig_Error_Loader error

text:
# Question
Title: Twig_Error_Loader error
I have been running a Drupal 8 site with Pixture Reloaded theme, based on Adaptive theme (in my .info file, the corresponding lines are:

'base theme': at\_core

'subtheme type': adaptive\_subtheme)

and suddenly, without having done any changes in the site code (just entered content), I get errors of type:

> The website encountered an unexpected error. Please try again later.
>
> Twig\_Error\_Loader: Template "themes/adaptivetheme/at\_core/templates/layout/html.html.twig" is not defined (Drupal\Core\Template\Loader\ThemeRegistryLoader: Unable to find template "themes/adaptivetheme/at\_core/templates/layout/html.html.twig" in the Drupal theme registry.). in Twig\_Loader\_Chain-\>getCacheKey() (line 115 of vendor/twig/twig/lib/Twig/Loader/Chain.php).

Also, I get similar error when trying to login in the admin, so I cannot clear any cache (if this could help). The site was working the same day earlier and the only thing I have done is enter new content (after having created a new view).

I would appreciate any help.

# Answer
> 2 votes
Eventually, I found out that some updates had been implemented in the theme and some modules and the problem was with the cache, not having been updated, so I run rebuild cache from Drush and the problem was fixed.

---
Tags: theming, 8
---


# Question
Title: How to insert PHP code into the Drupal 7 block with PHPFilter to enable a html form working?
* ```
<form action="run_pipeline.php" method="post">

Insert SRA  identifier <input type="text" name="email"><br> <input
type="submit" value="Run data processing pipeline"> </form>

<?php

?>

</body>
</html>

```

This code I have put to a custom block to make a webform to save data input to a file. Where to put the run\_pipeline.php which contains the code for saving data input to Excel and running Python scripts? Or should I put it right here in tags? Now it says: The requested page "/drupal/run\_pipeline.php" could not be found.

# Answer
Instead of writing php codes inside admin blocks better to create custom blocks and specify ur php file and write custom code there.
> 0 votes

---
Tags: input-formats, external-scripts
---


# Question
Title: Trouble with maximum registrants for RNG
I've tried to create an event with a maximum of 5 registrants and a maximum of 5 registrations to limit my tests on these modules. I was unable to limit the number of registrants to 5 when users can create multiple people registrations for an event.

Could you explain how to set an event with authenticated users able to register several other users without going out of the maximum registrant? I've already tried to set the Conflicts on Maximum registrants without success.

# Answer
> 0 votes
The current minimum and maximum registrant fields as found in RNG 1.5 are **per registration**.

Perhaps you are looking for maximum registrants per event?

---
Tags: rng
---


title: Drupal Translation Doesn't work

text:
# Question
Title: Drupal Translation Doesn't work
I am trying to translate articles/nodes on my site. I installed all required modules.

I have a custom node type.

This custom node type has some fields that are translatable and not translatable.

I checked this checkbox

I created custom view for the front page that contains nodes of custom type. But when I switch the language translation doesn't work.

Menu translation works. But the view nodes are not translated.

The interesting thing that if I visit my node by a full url path like this

`http://test.net/node/1`

Translation works fine.

I am outputting node properties in my template in the following way

```
          {{ node.title.value }}
   {{ node.field_description.value|raw }}
    {{ node.field_custom_body.value|raw }}

```

What can be wrong ?

**EDIT**

I have no option `Content language selected for page`

My view looks like this now

P.S I am using language switcher block to change language and it sets the session variable

# Answer
You have to configure a filter for the language in the the view:

FILTER CRITERIA

"Content: Translation language (= Content language selected for page)"

---

Btw. you have a big security problem in the node template, it is not allowed to apply the raw filter on a field that contains user input. You should use

```
{{ content.field_custom_body }}

```

instead to print the field.
> 2 votes

---
Tags: theming, 8, i18n-l10n, transliteration
---


# Question
Title: Enabling "entity translation" disables term translation in Drupal (name and description)
i want to translate taxonomy terms and their description text. When I enable the module "entity-translation" and check "Taxnomie-terms" in admin/config/regional/entity\_translation, the terms and descriptions get synchronized. Means: If I enter the German termname and description and switch to english and change it there, it also changes on the german translation.

The lables show:

* Name (all languages)
* Description (all languages)

And I don't know how to change that. Ideas for solving my problem welcome!

# Answer
Ad documented on the Entity Translation project page: "Title module allows to replace entity labels with fields to make them translatable." With the Title module you are able to replace the non-Field title and description properties taxonomy terms with Fields translatable with Entity Translation.
> 1 votes

# Answer
had the same issue, after hours of frustrating research we found the solution.

* please check if you have "title" module installed.
* then go to /admin/structure/taxonomy/\[vocabulary\_name\]/fields
* for title and description hit "replace"
> 0 votes

# Answer
Hours??? In my case it has been days!!! And I'm desperate (again!)

If Drupal is already counter intuitive by itself in general and even more for translations, taxonomy always has been a hundred times worse.

However, I did achieve a certain (not full) level of taxonomy translation through field (or entity) translation doing something like:

1. for the vocabulary ("Special") I went to: "Localize" under admin/structure/taxonomy/special/edit Save&Translate -\> NL:"Speciaal", IT:"Speciale", ES:"Especial"
2. for the term ("To be developed") I went to: nl/taxonomy/term/85/edit/nl or was it taxonomy/term/85/translate?? (this for each language). On both pages it says I have this URL alias for each language, but when I use that path (eg /nl/speciaal/te-ontwikkelen) I get a "Page not found" error. Same goes for /it/speciale/da-sviluppare, /es/especial/por-desarrollar Only Generic (Drupal's "Default") works: special/to-be-developed

Also the translated Terms of "to-be-developed" do not appear as options in the translated version of the "Special" Vocabulary when editing content. HOW does Taxonomy get to understand that both Vocabulary and Term already exist, have been translated and that these paths should work????

3. also did translation under admin/config/regional/translate/edit/9709?destination=admin/config/regional/translate/translate

What should be the next step should to get also the other languages to work (without creating additional term IDs)?

Additionally my hope was to have Taxonomy terms syncronized EVEN with entity translation (new translation of content -\> tax term already selected) as is possible with menu items to have just one instance in the list. Is this actually possible?

Also I have not been able to find the "language is in" option for the "Special" vocabulary in Views: admin/structure/views/view/special How can I get that?

And last but not least: path is not translated either they all go to /lang/special even if "Special" already has been translated to the other languages in all possible places (although you never know)

BTW one should definitely should NOT FORGET to also activate the field-translation options for Taxonomy (Vocabulary and/or terms) in several other places, before Drupal or Taxonomy even understand you really MEAN to use entity (or field?) translation all over the site (not just in only one expceptional place) and the above can even occur. Unfortunately after days of going through the impossible Drupal-Taxonomy-FieldTranslations labyrinth, I do not remember all the steps, nor the order I have taken, nor which of these steps were actually valid. Anyway several of these places, randomly (don't know if all) are: \- admin/structure/taxonomy/special/fields/name\_field \- to keep up common sense, indeed also in the Title module: admin/config/content/title \- in the content type: admin/structure/types/manage/\[content-type\]/fields/field\_category \- of course several additional things under the translation interface admin/config/regional/translate/translate not forgetting string refreshment admin/config/regional/translate/i18n\_string \- and I don't remember if somewhere else in Drupal's translation labyrinth (specifically having to activate entity (or field?) translations for taxonomy or vocabulary or terms...) Maybe some module configuration or special permissions...

Example at: http://europinion.is/special/to-be-developed (if it doesn't break of course) you can see: 1 - the Vocabulary menu item is translated, however linking to non translated path 2 - Term also appears, however linking to a path that gives error 3 - vocabulary/term reference appears translated in the content with "page not found" path again
> 0 votes

# Answer
The entity translation approach for taxonomy term can be a bit of a mess indeed.

I had created my vocabulary and terms before I enabled "**Field translation. Term fields will be translated through the Entity translation module.**" in my vocabulary settings (admin/structure/taxonomy/(*yourvocabulary*/edit).

As a result Views wouldn't properly output the translated term name and description (it would stick with the source translation).

**Solution:**

*Notice: the steps below are advised when enabling "Field translation", replacing the title and description field and re-saving each term isn't working out.*

1. I deleted and recreated the vocabulary from scratch,
2. enabled Entity translation on it first of all this time (note: it may require a patch to obtain this *Field translation* option, and running `update.php` may be required right after that),

3. replaced both the title and description fields with entity fields (using the Title module),
4. and finally added the terms again.
5. Once the terms and their descriptions where all there in the source language, I translated them one by one.

Mind you that it's possible that there's no "translate" link directly next to the term in the overview. To translate the term, click its "edit" link, and then you'll find "translate" tab.

This time Views would properly render the translated output of both the term name and description.

-\> On a sidenote: taxonomy fields may be more practical than select option fields in content types, especially when it comes to URL patterns and their translation. -\> When you accidentally enabled taxonomy translation and attempted to translate a term, and now the Entity Translation approach has no longer effect: go to the database and find the table `entity translation`. Find the term (by its TID), and assign a language to it in the `language` column (instead of `und`). In case it's still not working: also provide this language in the `language source` colum. Now the translate tab to appear again on the term's edit page.
> 0 votes

# Answer
The latest version (beta6) of entity translate now supports Taxonomy term translation
> 0 votes

---
Tags: i18n-l10n
---


# Question
Title: Multiple problems after updating to 7.54
I am working on a D7 site with the latest stable version of Commerce and several Commerce Contrib modules. I recently applied the core 7.54 update from 7.53 and it appears to have caused several problems with my DC set up; specifically 1) the Store Admin UI; 2) Cart Shipping Calculations; 3) the addition of Coupons; 4) the system message list (particularly for cart actions doesn't clear, and builds up).

First, all of these symptoms seem to be related to 7.54 because I have the same code base (same module versions) on a test server without the issues.

**Commerce Admin UI** whatever is happening has broken part of the commerce store ui. I cannot add line items to an order (not coupons, not products, not shipping). When I select one of the line item options and click "add line item" the spinning icon appears but it stops. The same behavior occurs regardless of which line item type I choose. I can confirm that this functionality is preserved with 7.53. This seems to be caused by an ajax error "Invalid Form POST Data".

**Commerce Shipping** I have three commerce shipping services, two flat rate, one based on the Postal Code and Weight Module. When a user proceeds through the cart checkout process, the Shipping calculation is not performed and the user can proceed to payment without shipping charges being applied to the order. I receive the follow watchdog error: "Invalid POST data" from ajax referred by mysite.com/checkout/294/checkout. If the user were to go back to checkout page, the shipping charge is calculated.

```
Warning: Missing argument 1 for addressfield_default_values(), called in /home/phislub9/public_html/sites/all/modules/commerce_shipping_postal_code_weight/commerce_shipping_postal_code_weight.module on line 81 and defined in addressfield_default_values() (line 374 of /home/phislub9/public_html/sites/all/modules/addressfield/addressfield.module).
Warning: Missing argument 2 for addressfield_default_values(), called in /home/phislub9/public_html/sites/all/modules/commerce_shipping_postal_code_weight/commerce_shipping_postal_code_weight.module on line 81 and defined in addressfield_default_values() (line 374 of /home/phislub9/public_html/sites/all/modules/addressfield/addressfield.module).
Notice: Undefined variable: field in addressfield_default_values() (line 375 of /home/phislub9/public_html/sites/all/modules/addressfield/addressfield.module).
Notice: Undefined variable: instance in addressfield_default_values() (line 375 of /home/phislub9/public_html/sites/all/modules/addressfield/addressfield.module).
Notice: Undefined variable: instance in addressfield_default_values() (line 376 of /home/phislub9/public_html/sites/all/modules/addressfield/addressfield.module).
Notice: Undefined variable: field in addressfield_default_values() (line 408 of /home/phislub9/public_html/sites/all/modules/addressfield/addressfield.module).
Notice: Undefined variable: instance in addressfield_default_values() (line 409 of /home/phislub9/public_html/sites/all/modules/addressfield/addressfield.module).

```

I am led to believe that this is an issue with core version 7.54 because these errors don't occur on the 7.53 codebase.

**Commerce Coupon** Adding percentage based coupons also fails with the "Invalid Post Form Data" notification in watchdog. Coupons can be input but they are not applied when submitted. The form simply clears.

**System Message Box** Unclear if this is related, but the system message box also seems to be affected. The system message box keeps every cart action in the box, leading to a larger and larger box. This clears after flushing the cache as an admin, but users do not have this option and therefore cannot clear the message box.

I'm not sure what else to add here, other than recently the server has been throwing PDO errors and crashing with the mysql server going away. It is a large codebase (over 100 modules).

**UPDATE** the module suggested in the comments here worked. Truncating the cache tables did not work.

# Answer
> 1 votes
Try to apply the patches that commerce kickstart uses .. https://www.drupal.org/project/commerce\_kickstart/releases/7.x-2.45

where

is form related

the others may not be needed:

---
Tags: 7, commerce, ajax
---


title: Views Bulk Operations skip confirmation

text:
# Question
Title: Views Bulk Operations skip confirmation
I have defined a custom action for a VBO.

```
function expense_action_info() {
  return [
    'expense_finalize_action' => [
      'type' => 'node',
      'label' => t('Approve and finalize expense'),
      'behavior' => ['changes_property'],
      'configurable' => TRUE,
      'vbo_configurable' => FALSE,
      'aggregate' => FALSE,
    ],
  ];
}

```

I've also created a configuration form for this action and rendered it along with the view.

```
function expense_finalize_action_form($settings, &$form_state) {
  $form['kickback_note'] = [
    '#type' => 'textfield',
    '#default_value' => 'new'
  ];
  return $form;
}

function expense_finalize_action_submit($form, $form_state) {
  return ['kickback_note' => $form_state['values']['kickback_note']];
}

```

When I submit the VBO I've redirected to page of this custom form and I need to click on the Next button to proceed the action. As I have provided required values in the form I need to skip this step. Is it possible?

# Answer
> 0 votes
In your view, under your field configuration, at "select bulk operation" section under the action there should be a "Skip confirmation step" option; uncheck it and you're ready to go

---
Tags: 7, views
---


# Question
Title: Site offline: The mysql error was: Access denied for user '[cpaneluser]'@'localhost' (using password: NO)
I'm somewhat new to drupal and I was handed a broken site to take a look at it.

The site is hosted on a godaddy shared hosting site. I'm not sure what they did to it but it is unable to connect to it's database anymore. I verified that the setttings.php has the correct credentials (it did not but it does now) but it still cant connect. The url is desoto.org.

I'm getting the following errors:

Notice: Undefined index: host in /home/desotoorg/public\_html/includes/database.mysql.inc on line 62

Notice: Undefined index: path in /home/desotoorg/public\_html/includes/database.mysql.inc on line 63

The mysql error was: Access denied for user 'desotoorg'@'localhost' (using password: NO).

What is odd is that the user desotoorg is the cpanel system user and not the user that I have configured to access the drupal database.

Any ideas as to what would cause this? Godaddy seems to thing that everything is running fine and that cpanel has all of the right permissions.

Thanks!

# Answer
> 0 votes
You should check your sites/default/settings.php file for a line like this:

```
$db_url = 'mysql://dbname:dbuserpassword@localhost/appname';

```

This line describes the url used by drupal to connect to the database used by drupal (the syntax above assumes mysql). Make sure that the password is correct and matches the latest password for the database user. These passwords often change when a site is compromised and then the site stops working.

---
Tags: database
---


# Question
Title: How to add "Add to Cart" button using Ubercart?
I'm building a website on **Drupal 8** that involves kids videos, that can be sold as separate files. I'm using **Ubercart** module.

I'd like to know how I can put an "Add to cart" button, linking the video content page with the appropriate cart page.

Please put forward your opinions.

# Answer
> 2 votes
According to this answer:

> ... The content type has to be an Ubercart product content type, then the add-to-cart button will automatically show up on that content type along with all the other fields that are necessary for an Ubercart product like price, sku, etc.
>
> To make a content type an Ubercart product content type, edit the content type at /admin/structure/types/manage/{name of content type}, choose the "Ubercart product settings" tab in the lower left of the page, select "Content type is a product", then save the content type.

---
Tags: 8, ubercart
---


# Question
Title: How can I change the author of a node before it is saved with hook_entity_presave()?
I have added code in a node presave hook before cloning a node as below to change it to the current user id

```
 $entity->setRevisionAuthorId($current_user);

```

and then I check with $entity-\>getRevisionAuthor and it has been changed in that presave function, however upon saving the author reverts back to the author of the original node that was cloned.

What is happening ? thanks

# Answer
I added $entity-\>setOwnerId($current\_user) and that worked
> 10 votes

---
Tags: 8, nodes
---


# Question
Title: How can I add a custom form to the output of a controller class?
I have a controller in my custom module. Inside this controller I need to render a whole bunch of different things (some basic html, multiple forms, etc). My main problem is I can't figure out how to

1. Properly load a Drupal 8 custom form
2. Then get that form into an acceptable format to pass to the #markup output of the controller.
3. Keep in mind this form is mixed in with other html that will be a mish-mash of lots of stuff not shown here (I've trimmed it down to show a basic example)

My controller code looks like this currently:

```
<?php

namespace Drupal\my_module\Controller;
use Drupal\Core\Controller\ControllerBase;

class SingleNodeProcessor extends ControllerBase {

  public function processSingle($nid) {
    $markup = '<div class="process-heading">' . $this->t('My custom Form Is below but there will be alot more html than just the form. So this is just an example.') . '</div>';

    $form = $this->formBuilder()->getForm('Drupal\my_module\Form\MyFormClassGoesHere', $nid);
    $markup .= $form; //this is a render array, how do I turn it to html so it can pass to #markup??

    return [
      '#type' => 'markup',
      '#markup' => $markup,
    ];
  }
}

```

# Answer
I think you want to return a render array, instead of markup. Because the from needs to stay as a render array, your best bet it to bring your content content to the same format instead of the other way. In your example:

```
public function processSingle($nid) {
  $build = [];
  $build['heading'] = [
    '#type' => 'markup',
    '#markup' => '<div class="process-heading">' . $this->t('My custom Form Is below but there will be alot more html than just the form. So this is just an example.') . '</div>',
  ];
  $build['form'] = $this->formBuilder()->getForm('Drupal\my_module\Form\MyFormClassGoesHere', $nid);
  return $build;
}

```
> 9 votes

# Answer
The problem is that render arrays of the #markup type run the resulting markup through XSS filtering, thereby filtering out many tags. (see Render API docs). In this case it will filter out the form tags.

The correct way to do this, according to the docs:

> If your markup needs any of the tags not in this whitelist, then you can implement a theme hook and/or an asset library. Alternatively, you can use the key #allowed\_tags to alter which tags are filtered.

So the solution is to either pass some tags to #allowed\_tags in the render array or (the better solution), use #theme in your render array instead of simple #markup.
> 2 votes

---
Tags: 8, forms, page-controller
---


# Question
Title: How can I change the published state of a node before it is saved with hook_entity_presave()?
I tried adding this in entity\_presave `$entity->setPublished(0);` but the node still gets saved as published. How can I make it be set to draft?

# Answer
> 4 votes
I have tested with hook\_entity\_presave() and setPublished(0) and setPublished(FALSE) both worked. So the issue is somewhere else.

If you have workbench moderation installed, you may need to set it to one of your moderation states that set it to unpublished.

See admin/structure/workbench-moderation/states

```
$entity->set('moderation_state', 'draft');

```

or

```
$entity->set('moderation_state', 'unpublished');

```

or perhaps a custom moderation state.

---
Tags: 8, nodes, workflows
---


# Question
Title: Have configuration form use a different theme than the currently set Admin theme
I built a custom configuration form with the following settings

The contents of my aaep\_settings\_main.routing.yml

```
my_settings:
  path: '/admin/config/system/my_settings'
  defaults:
    _form: 'Drupal\my_settings\Form\SettingsForm'
  requirements:
    _permission: 'administer site configuration'

```

And then inside my SettingsForm.php I have

```
class SettingsForm extends ConfigFormBase {

protected function getEditableConfigNames() {
    return array(
        'my_settings.settings',
    );
}

public function submitForm(array&$form, FormStateInterface $form_state) {

    $this->config('my_settings.settings')
         ->set('test', $form_state->getValue('test'))
         ->save();
}

public function buildForm(array $form, FormStateInterface $form_state){
    $config = $this->config('my_settings.settings');
    $form['test'] = [
         '#type' => 'textfield',
         '#title' => t('Test'),
         '#default_value' => $config->get('test'),
    ];
}

```

It works just fine, but when I visit the page it's using the admin theme instead of the regular theme. I'm assuming that's because it's using a configuration form and extending ConfigFormBase. I'm assuming that that's the default behavior. But is there a way to override that and have my configuration page use my site theme instead?

# Answer
You can control this in the route definition.

If you give non admin users access to the form they will see it in a regular theme:

```
my_settings:
  path: '/admin/config/system/my_settings'
  defaults:
    _form: 'Drupal\my_settings\Form\SettingsForm'
  requirements:
    _permission: 'access content'

```

If you want to have admins see the form in a regular theme then move the path outside of `/admin`:

```
my_settings:
  path: '/other-path/my_settings'
  defaults:
    _form: 'Drupal\my_settings\Form\SettingsForm'
  requirements:
    _permission: 'administer site configuration'

```

Or do both at the same time.

**Details:**

If you give a non admin user permission for an admin route, then the form will be displayed in the regular theme, because the admin theme is only accessible for admin users or users who have the "administration theme" permission.

Whether a route is considered as admin route is controlled by the route option `_admin_route`. If this option is not set, it is added by `AdminRouteSubscriber::alterRoutes` to all routes with an admin path:

```
  protected function alterRoutes(RouteCollection $collection) {
    foreach ($collection->all() as $route) {
      if (strpos($route->getPath(), '/admin') === 0 && !$route->hasOption('_admin_route')) {
        $route->setOption('_admin_route', TRUE);
      }
    }
  }

```

If you want to override this you can set the option to false:

```
  options:
    _admin_route: FALSE

```
> 2 votes

---
Tags: theming, 8
---


# Question
Title: Why does my user signup request have no response back?
I have a Drupal website hosted on a LAMP server (dev machine on intranet).

When tried to signup using the registration page (signup page for a user), the page keeps loading with message "waiting for server".

When tried to check using firebug add on in Firefox, I saw in the "network" tab that there is no response back for the signup request.

Does it have to do with the SMTP configuration within the server?

But once logging in with admin and checking the "people" tab shows that the user is created but there was no email sent to verify the email address

So I believe the next step after user creation (according to code) gets failed due to which there is no response and email not sent. Appreciate any help on this.

# Answer
> 0 votes
was able to resolve this. The problem was with the incorrect configuration of SMTP relay host which was blocking the sending email part while signing up, due to which the request was incomplete with no response. If anyone has the same problem it should probably be with the SMTP configuration settings on the server

---
Tags: users
---


# Question
Title: Get field value from referenced entity in twig loop
I have a content type with a multiple referenced field and I need to iterate trough each item and display the item information in a table but I don't know and didn't find a way to access the content field information like the value of a specific field.

Example: I have a content type called Task and in Task I have multiple Entity Reference to Worker content type, Worker has title, name and phone. How can I iterate each worker and display the information in a table?

What I want to do is to override **node--task.html.twig** to do something like this:

Assuming that we have a field\_workers field in task content type.

```
<table>
   <thead>
     <tr>
       <th>
         Name
       </th>
       <th>
         Phone
       </th>
     </tr>
   </thead>
   <tbody>
    {% for worker in content.field_workers %}
     <tr>
       <td>
        {{worker.field_name.value}}
       </td>
       <td>
         {{worker.field_phone.value}}
       </td>
     </tr>
     {% endfor %}
   </tbody>
</table>

```

Is it possible? Thank you!

# Answer
You want to work with node instead of content.

something like this should work

```
{% for item in node.field_workers %}
 {{ item.entity.field_name.value }}
{% endfor %}

```

See Entity API Cheat Sheet and Twig and Entity Field API or how to take control of node.html.twig (my blog post) for more information.
> 9 votes

# Answer
As @Berdir explains in http://www.md-systems.ch/en/blog/techblog/2017/02/20/twig-and-entity-field-api-or-how-to-take-control-of-nodehtmltwig you have two options, use the `node` entity (see Berdir's answer) or the render array in `content`. For the content approach you have to put the table row in a second node template:

**node--task.html.twig**

```
<table>
   <thead>
     <tr>
       <th>
         Name
       </th>
       <th>
         Phone
       </th>
     </tr>
   </thead>
   <tbody>
     {{ content.field_workers }}
   </tbody>
</table>

```

**node--worker--table.html.twig**

```
     <tr>
       <td>
         {{ content.field_name }}
       </td>
       <td>
         {{ content.field_phone }}
       </td>
     </tr>

```

Disadvantage obviously is you need two templates. Advantage is, you can render the Worker fields how they are configured in UI and you can use text filters. Use a separate view mode `table`, so that you can display the Worker content type in other places as normal. You might also need to remove html from the `field--field-workers.html.twig` template if it's in the way of the table structure.
> 3 votes

---
Tags: theming, 8, entities
---


# Question
Title: How to use the D3.JS library for data visualization?
What are the available options for using the D3.js library in Drupal for creating data visualizations?

D3.js (Data-Driven Documents) appears to be a charting engine with an ever growing popularity. So I wonder how to somehow use D3.JS as a charting engine.

# Answer
> 6 votes
There are at least 3 contributed modules which may help to use the D3.js library (open source, released under the BSD license) in a Drupal 7 site:

* Charts and Graphs:

> Charts and Graphs is an API for developers. It can be extended by third-party modules that want to add their own charting implementations. It does nothing by itself. It should only be installed if some other module requires it.
* D3 (Alfa release only):

> creates visualizations as libraries (alpha version only) which allows one to add/remove visualizations, share them between modules, and integrate them with (for example: Views) through library .info files.

The Basic module configuration presentation provides a short intro about how to use the module in combination with Views.
* Forena

If you decide to not use any of these modules, it may help to get started with D3.js integration in Drupal by just looking at the code of these modules. Either to roll your own D3.js cookies via a custom module, or at least to get an idea of the required effort.

The D3.JS Tutorial is a great place for documentation about how to use this library.

# Answer
> 2 votes
The Drupal 8 version of Charts (disclosure, I'm a co-maintainer) supports three libraries:

* C3.js (new as of D8).
* Google Charts and Highcharts (both similar to what is already in D7, now also for D8).

Some more details about how **`C3.js`** relates to **`D3.js`**:

> **C3** is a D3-based reusable charting library, more details about it can be found at c3js.org.

The current (D8) version of Charts is already available on Github, which is about to be released on Drupal.Org as the **Alfa1** version of Charts also, as part of the newly launched `D8Charts` initiative (which got launched on Mar 10, 2017).

---
Tags: charts
---


# Question
Title: How programmatically display the Image field before Taxonomy name in Better Exposed Filters?
Third day I'm looking for a solution, but I can not find an answer. I use Taxonomy term as a filter (Better Exposed Filters) on Views. To Taxonomy term added a field image. How programmatically display the Image field before Taxonomy name in Better Exposed Filters?

I tried modules taxonomy\_icon, vocabulary image, taxonomy image All of them do not provide an opportunity for filters Views to derive taxonomy terms in the form of "image taxonomy name".

# Answer
> 1 votes
I was prompted how to do it. Thanks a lot to xandeadx.

```
function MYMODULE_form_views_exposed_form_alter(&$form, &$form_state) {

foreach ($form['TAXONOMY_ELEMENT']['#options'] as $tid => &$name) {
    $term = taxonomy_term_load($tid);
    $name = '<img src="' . file_create_url($term->FIELD_IMAGE['und'][0]['uri']) . '" />' . $name;
  }
}

```

In my version TAXONOMY\_ELEMENT = tid\_1

---
Tags: 7, taxonomy-terms, media
---


title: Display the taxonomy term as an image

text:
# Question
Title: Display the taxonomy term as an image
I'm trying to display the taxonomy term (filter (Better Exposed Filters) on Views) as an image. I added an image field, upload an image (marker). Create template **views-view-field--maps--field-type.tpl.php**. I found example how to make theming of taxonomy-term here: http://www.milesjcarter.co.uk/blog/web-design-development/drupal-views-templating-tutorial-outputting-respective-image-fields-multiple-taxonomy-term-references

My code looks like:

```
if(isset($row->field_field_type)) {
    $term = $row->field_field_type;
    foreach($term as $type){
        render(field_view_field('taxonomy_term', $type['raw']['taxonomy_term'], 'field_marker', array('label'=>'hidden', 'settings' => array('image_style' => 'thumbnail'))));
    }
}

```

For some reason, the code does not replace taxonomy term, it just show me messages:

> Notice: Only variables should be passed by reference in include() (line 8

What could be the reason? I would be grateful for any advice.

I try dpm:

```
dpm(render(field_view_field('taxonomy_term', $type['raw']['taxonomy_term'], 'field_marker', array('label'=>'hidden', 'settings' => array('image_style' => 'thumbnail')))));

```

And it show me this:

```
<div class="field field-name-field-marker field-type-image field-label-hidden"><div class="field-items"><div class="field-item even"><img typeof="foaf:Image" class="img-responsive" src="http://localhost/sites/default/files/styles/thumbnail/public/1.png?itok=A6-EJb27" width="63" height="100" alt="" /></div></div></div>

```

I know that there is a module Taxonomy Image I tried to install it, but after activation necessary functionality was not added to my site.

# Answer
I've got solution. Thanks xandeadx for the help

```
function MYMODULE_form_views_exposed_form_alter(&$form, &$form_state) {
    foreach ($form['TAXONOMY_ELEMENT']['#options'] as $tid => &$name) {
        $term = taxonomy_term_load($tid);
        $name = '<img src="' . file_create_url($term->FIELD_IMAGE['und'][0]['uri']) . '" />';
    }
}

```

TAXONOMY\_ELEMENT = tid\_1
> 0 votes

# Answer
There are multiple ways to do it. The easiest way would be to use views. You can create a view of taxonomy terms with only an image field and display it as a view block.

See an example of view below.

Let me know if you need any help.
> 1 votes

---
Tags: 7, taxonomy-terms, media
---


title: Library dependancies not loading

text:
# Question
Title: Library dependancies not loading
The dependency core/jquery.ui is not loading into the theme. jQuery is loaded as it is included by default but jquery.ui refuses to load.

```

#theme.libraries.yml
popup:
  version: 1.x
  js:
    js/popup.js: {}
  dependancies:
    - core/jquery
    - core/jquery.ui

```

```
#theme.info.yml

libraries:
  - theme/popup

```

I have also tried attaching the library using the code below, but still no luck.

```
// theme.theme
function theme_page_attachments_alter(&$page) {
  $route = \Drupal::routeMatch()->getRouteObject();
  $is_admin = \Drupal::service('router.admin_context')->isAdminRoute($route);
  if(!$is_admin) {
    $page['#attached']['library'][] = 'theme/popup';
  }
}

```

I have seen multiple references to core/jquery.ui throughout drupals files. So am a little confused.

I feel like i must be missing something obvious.

jQuery UI will load in fine if you are logged in, but again i believe this is included by default for admin users.

# Answer
> 0 votes
For those that are trying to use the built in jquery ui you must include -core/drupal.dialog as a dependency in your theme.libraries.yml for it to work

# Answer
> 0 votes
You made a typo in your theme.libraries.yml, dependancies should be dependencies.

---
Tags: javascript
---


# Question
Title: What could cause the Wysiwyg module / CKEditor randomly disappearing and coming back?
I've successfully installed and configured the Wysiwyg module with CKeditor. However, it keeps disappearing. First it disappeared when I enabled another module (cannot remember which, but thankfully it wasn't necessary so I could disable it again). I was just lucky to figure that out.

But now it disappeared again, and I don't know what happened this time. I didn't install any new modules.

Any ideas why this is happening? Is the wysiwyg module too unstable to use? If so, what's the alternative?

EDIT:

The issue keeps coming back, but I have discovered something new: if I disable a module (and optionally enable it again), apparently pretty much any module, then the wysiwyg editor appears again(!)

So it seems any change in the modules installed brings the editor back. I have only tested this in localhost, if that has anything to do with it.

# Answer
> 0 votes
go to modules and find jQuery Update module, and put it to version 1.8 That should fix the issue.

# Answer
> 0 votes
The issue might be with ckEditor library. Try to remove this library from sites/all/libraries and upload the new one from here :

http://download.cksource.com/CKEditor/CKEditor/CKEditor%203.6.5/ckeditor\_3.6.5.zip.

For reference : https://www.drupal.org/node/1839322enter link description here

# Answer
> 0 votes
No guarantee it will help, but I think it's worth trying: increase your php memory limit (eg add like 25 to 50% of it, just to try) and try again.

Since you're experiencing problems because of "enabling" modules, and since they seem to temporary disappear if you disable some of them again, it could well be that you've reached a memory limit that causes these kinds of related problems ...

# Answer
> 0 votes
This problem appears to be coming from bad aggregation of JavaScripts. I had a similar experience where the bundled JavaScript contained an occasional syntax error (can be caused by any other module, not only wysiwyg)

While clearing the cache (which also happend if you enable/disable a module), the JavaScript will be rebuilt.

I particulary noticed this with the advagg module.

---
Tags: wysiwyg
---


# Question
Title: Field groups not showing when nested using field type HTML
I'm using Drupal 7.34, Profile2 module, Field groups 7.x-1.4.

When building a form with nested field groups and using the fieldset field type, my form renders properly.

When I configure my form like this:

It renders into this, showing nothing but the Title and Save button:

There is nothing in the generated HTML as well, i.e. not hidden div's or something. The HTML markup just isn't there.

When I configure my form like this (changed nested fieldgroup element from HTML to Fieldset):

It renders into this, showing all:

My goal is to have some nested HTML elements, which I am able to style in a theme. Am I doing something wrong with nested HTML elements?

Thanks, Eric

# Answer
> 0 votes
the solution and patch can be found here: https://www.drupal.org/node/1503094#comment-11981615

---
Tags: 7, entities
---


# Question
Title: How do I insert the node ID into a link field?
Building a site with content types Business, Product, and Review. Currently when users click a business name, they are taken to the Full Content view for that Business (e.g. sitename.com/business/\[business name\] since we are using PathAuto).

Created a custom View called Profile (sitename.com/profile) with a contextual filter that shows a selected Business as a rendered entity followed by two view attachments that show their Products and Customer Reviews.

We can manually type sitename.com/profile/6 into a browser and see a business with the attachments for products and reviews, but we are having trouble getting users there.

Tried adding a new field to Business with a default value and tokens to generate a URL to the business' profile view (e.g. Link with a default value of "/profile/\[node:id\]"). This field would be hidden on the input form for Business but displayed on the Full Content view.

We have not been able to get this working and do not know a better way to approach the challenge. If it is possible to get the Products and Reviews to display on the Business content page without using the Profile view (e.g. User clicks a Business name and sees their profile with products and reviews underneath), that would also meet the requirement.

Would prefer to do this without custom coding if possible, but acceptable if it is the only or best way. Happy to answer questions for clarification or provide links to the site (still in beta) if it would help.

# Answer
> 1 votes
Going from node/6 page to profile/6 page (which displays products and reviews) there is a simple module that can help with this https://www.drupal.org/project/field\_token\_value

It will allow you to add a field `PROFILE PAGE` hidden from the editor and can be configured to have the value of

```
<a href='/profile/[node:nid]'>profile page</a>

```

after that go to the content type display `admin/structure/types/manage/CONTENTTYPE/display` to configure where should be displayed

The field will not be available on the edit form and after saving it will hold a link to `profile/[nid]`

Above module works in both drupal 7 and 8

### More involved alternatives

you could use https://www.drupal.org/project/linked\_field and https://www.drupal.org/project/field\_permissions (drupal 7 & 8)

For drupal 7 projects https://www.drupal.org/project/token\_field does the same thing

# Answer
> 0 votes
This sounds like another job for my friend EVA (Entity Views Attachment). Rather than having two Views attachments, you could rework those two displays to become entity views attachments and have them show up on your `sitename.com/business/[business name]` page.

From the module description:

> "Eva" is short for "Entity Views Attachment;" it provides a Views display plugin that allows the output of a View to be attached to the content of any Drupal entity. The body of a node or comment, the profile of a user account, or the listing page for a Taxonomy term are all examples of entity content.
>
> The placement of the view in the entity's content can be reordered on the "Field Display" administration page for that entity, like other fields added using the Field UI module.

---
Tags: views, entities
---


# Question
Title: How to export (send) image from website to Instagram?
I'm working on a social network website based on Drupal7, This social network is based on photos and users may upload photos and they are accessible in their profile. I need to equip the site to contact to the *Instagram* profile of users and they can send images from my website to their profile in Instagram. I checked the Instagram Block and Instagram Feeds and Drupalgram modules, but from I understand these modules only import images from Instagram, non of them export images to Instgram. How do I can send Images from my website to Instagram?

# Answer
> 2 votes
You can use module InstaPost for posting nodes to Instagram. Some details about it (from its project page):

> This module allows users to post nodes automatically to the online mobile photo-sharing, video-sharing, and social networking service Instagram.

Disclosure: I'm the maintainer of this module.

# Answer
> 1 votes
The Instagram Block and Instagram Feeds and Drupagram modules work with Instagram.

> ***Instagram block*** integrates with Instagram and creates a block containing your most recent instagram posts.
>
> ***Instagram Feeds***: This is a Feature module. It allows you to create Instagram feeds for your site that will download images from Instagram using filtering by hashtags and / or usernames.
>
> ***Drupagram*** In this early implementation the module will interact with the Instagr.am API and be able to fetch media items. Advanced methods like relationships between Instagr.am users and such will be added later on.

But about posting to Instagram

# Instagram didn't allow uploading through their API by design

# Answer
> 1 votes
By default you cant upload your image to instagram but I suggest you using if this then that service,it is awesome, and using `Email to instagram` feature, then in your drupal you can send your blog image automatically after node create to specified email then it posted to you istagram automatically.

helper links :
link1
link2

---
Tags: media
---


title: How to show Personal reading rate?

text:
# Question
Title: How to show Personal reading rate?
I use view & seen module make a bulletin .

How can I survey user "reading rate", I want to know:

* if everyone read every article, or
* which article specific person do not read yet.

Any help?

# Answer
Using the Flag module seems like a no brainer to me to get this to work. Combine it with the Rules module to have a custom (not global) flag automatically flag such article, based on whatever rules Event that would fit. And since Flags are fieldable, you could even add an extra field to it to let your user indicate some type of rating, if that's what you want.
> 1 votes

---
Tags: 7, users
---


title: Custom PDF template in Commerce Billy

text:
# Question
Title: Custom PDF template in Commerce Billy
I have installed Commerce Billy module on my website.

Then upon ordering I get this PDF with this layout.

But I want to change the table displayed, because I've created some custom fields in it and I want to display it also in the table.

Any help will be greatly appreciated.

# Answer
> 5 votes
This table is actually the rendered view 'Line items (Commerce Line Item)' which is created in code by Drupal Commerce. So all you have to do is to modify this view to your needs.

To further customize the display of your invoice, you can make a copy of `css/pdf.css` and `themes/commerce_order--commerce_order--pdf.tpl.php` located in `commerce_billy_pdf` folder into your custom theme and experiment.

# Answer
> 1 votes
If you'd like to display field output from custom fields, the simplest way is to put tokens in one of the `admin/commerce/config/billy-invoice/pdf` text areas. I regularly place the pdf footer text in the `commerce_order--commerce_order--pdf.tpl.php` and use the footer text area to place text and tokens like `Customer ID: [current-user:field-customer-id]` and do the styling and placement via CSS.

---
Tags: commerce
---


# Question
Title: Copying a site to a multi-site installation
On Server A (debian) drupal was installed by the package manager. So basically the codebase is at: `/usr/share/drupal7` with `/usr/share/drupal7/sites` symlinking to `/etc/drupal/7/sites`.

Server B has basically the same setup (ubuntu).

The multi-site feature is configured like that: At `/etc/drupal/7` we have a apache.conf:

```
Alias /site1 /usr/share/drupal7
Alias /site2 /usr/share/drupal7

<Directory /usr/share/drupal7/>
        Options +FollowSymLinks
        AllowOverride All
        order allow,deny
        allow from all
</Directory>

```

I copied the Site from A to B. In A it was installed at /sites/default so I copied it to /sites/default at B. The index page (www.foo.com/drupal7) is redirected to /sites/default. So basically it works.

But if I go to e.g. www.foo.com/drupal7/members I get: 404: The requested URL /usr/share/drupal7/index.php was not found on this server.

Also: If I want a multisite like www.foo.com/site1 I create it at /sites/foo.com.site1

Question 1: How can I confiure it so it works on / rather than on /drupal7? So basically I'd like to use this site "normal" on /sites/default but another site at /sites/site1.

Question 2: How can I fix the 404 error?

# Answer
> How can I confiure it so it works on / rather than on /drupal7

This has to do with your Apache `VirtualHost`. It probably is pointing to `/usr/share/` instead of to `/usr/share/drupal7`. So in order to access the content in the `drupal7` folder, you need to add the folder to the url.

> Question 2: How can I fix the 404 error?

Relating to:

> But if I go to e.g. www.foo.com/drupal7/members I get: 404: The requested URL /usr/share/drupal7/index.php was not found on this server.

The first thing is figuring out if there is an `index.php` file there. If so, does it have the correct permissions?

It seems to be an Apache error, not a Drupal error at this point. ;)
> 1 votes

---
Tags: 7, multi-sites
---


# Question
Title: User contributed image gallery, per node
Working on a new Drupal 7 based site. Put together a few sites back in the 5 days, but lots has changed.

I'm looking to allow users to upload images to a particular content type, and to show those images as a gallery. Restated - I'd like user X to be able to create a node, and then users X, Y, Z, P, D, and Q to each be able to upload images to that node. (Looking to the future, I want people to vote on images, but let's keep it simple, for the moment.)

My sense at this point is that I have to create an entity type for image, use entity reference to point from the images to their parent node, and use views and probably eva to show the galleries on the parent node.

Question 1: Am on the right track here?

Question 2: How should I handle the 'allow anyone to upload images' piece? I'd like there to be a rather simple opportunity, when a user is viewing a parent node, to upload an image or provide an image url, and for the image node to be created and appropriately associated.

Thanks for any help.

# Answer
You could just use the modules: http://drupal.org/project/references and http://drupal.org/project/nodereference\_url

This would work if users create new images as nodes. With the help of the second module you achieve that the relation between image node and parent node is automatically created and it also allows to set a link directly on the parent node (a la: create image for this content).

I don't think that you would need EVA in this case. The view to show all images per parent content is straightforward with one argument based on the relation.

What I describe above is pretty much the way you would have done it in Drupal 6 as well. You might get additional features (and maybe complexity) using the module entity reference and EVA.

Hth.
> 0 votes

# Answer
Another solution would be to have users create a node for each image and then select the "gallery" the photo is assigned to. You can use the built-in taxonomy term reference for that.

To automatically prefill a term reference field (to upload a photo for a given gallery) you can use the prepopulate module.
> 0 votes

# Answer
To answer your questions,

> Question 1: Am on the right track here?

Yes!

---

> Question 2: How should I handle the 'allow anyone to upload images' piece? I'd like there to be a rather simple opportunity, when a user is viewing a parent node,

When displaying the gallery, display the form for users to add a new image.

---

> to upload an image or provide an image url,

You can add 2 fields,

* Field image (image field)
* Field image url (link?)

You will need to add logic, determine precedence.

Another option, add a third field that allows someone to check if it's an image or a file and then based on that, present the right field.

For your display,

If it's an image url, you'll need to decide if you'll either download the image or just use the URL provided. (You mentioned in the future voting, so people could down vote problematic/broken links.)

---

> and for the image node to be created and appropriately associated.

https://www.drupal.org/project/entityreference\_prepopulate

:)
> 0 votes

---
Tags: 7, views, media
---


# Question
Title: Twig Tokens in Views not Rendering Inside an HTML Element
I'm using views to create a custom block of shortcut icons and need the images to link to the corresponding content. Using *Rewrite Results* I can overwrite the output of the view and have an `anchor tag` wrap around the image, however when I inspecting the output on the site, the `href` is blank making the images useless as links. Everything else renders though.

The view uses two fields, all from the same content type (shortcut). It consists of an image and a URL field. The image field is called first and then hidden to get the tokens, and the URL field holds the actual rewrite text. All of the these Twig tokens are listed as available within the *Replacement Patterns* dialog box.

```
<a href="{{ field_url__uri }}">
{{ field_image }}
</a>
<br>
{{ field_url }}

```

Does Twig Debug affect the output for content like this? Is there another format I should be using? I tried calling and hiding via CSS the `{{field_url}}` first, before the rest of the rewrite text to see if it had to do with render inheritance but it still didn't change the blank `href` output.

Any insight on why the Twig token won't render inside HTML would be GREATLY appreciated. Thank you.

# Answer
> 0 votes
Problem solved. There were two issue at play; first off when I was messing with the Twig templates to trying and format the view the hard way, I inserted an extra `<a href="">` in one of the templates and failed to remove it. My template was wrapping the empty tag around the properly generated content making it useless.

The second problem was that for some odd reason, the block was calling/using the same custom theme hook twice. I haven't figured out what was causing this error, but deleting the bock and forcing the new one to revert to a more general template hook solved the rendering issue.

However Twig debug still shows that there are two custom theme hooks of the same name available for use. No clue what is causing this behavior.

---
Tags: views, theming, 8, tokens
---


title: Comment Display

text:
# Question
Title: Comment Display
How can I change the way that comments are displayed on my Drupal 8 page?

I can modify the display of some of the fields at

```
/admin/structure/comment/manage/comment/display

```

but this allows for rather limited changes only, e.g. doesn't allow changes to titles and links.

I can create my own view to get a custom layout for the comments, but currently ctools, layout\_plugin, and page manager for Drupal 8 are still an alpha release, and therefore I can't attach the view as a panel to my node.

Anyone got any ideas how to solve this? Where could I modify the display of my comments programmatically?

# Answer
> 4 votes
Take /core/modules/comment/templates/comment.html.twig file from your Drupal installation directory and place it in the directory of the theme that you are using in the *templates* folder, for example /themes/bootstrap/templates/. Modify that file to change the way your comments are displayed. You might have to clear the cache to see your changes.

It may be worth creating a sub theme first, so that you don't loose your changes when you update the theme.

---
Tags: 8, comments
---


# Question
Title: Unable to access site after deleting an entry from the database
The entry *views.view.media* from the config table in phpmyadmin was accidentally deleted. When visiting the site it giving the error ***The website encountered an unexpected error. Please try again later***. I'm unable to login or access any page. What can I do to fix this problem? It's drupal 8.2.4.

# Answer
You can try installing the views in a similar configuration to your current site, on another install, and then copy that row from the database in that install to your current site.
> 0 votes

---
Tags: database
---


title: Duplicated nodes of thew view

text:
# Question
Title: Duplicated nodes of thew view
I created a view, that is simple page containing nodes of a specific content type.

It had worked before I started to translate nodes. I added a new translation for my node and now I have duplicated entries of the same node displayed on the page.

I have solved this problem for one view with just enabling aggregation.

But with this one it doesn't work.

It outputs the same node twice. And the language is the same, but at first they have different languages.

Really, I don't understand what is going on with the translation modules, or what causes such a weird behavior. I have asked a lot of questions about translation in Drupal, and each time I try to do anything related to the translation, I get a new error.

Maybe I am going crazy, but something terrible is happening with the Drupal translation modules.

Please suggest how to deal with this ?

# Answer
I can suggest you an alternative approach. In your views filter area, create a new filter, based on the current user's language.

**How to do it:**

Views: add filter criteria -\> Content: Translation language Check the checkbox labeled "Interface text language selected for page"

Another thing, you can go to Views overview page, and then Views settings tab -\> Show SQL query option.

**How to do it:**

Go to admin/structure/views/settings Check this option

In this way this will always show the query that gets executed. I suggest you copy it it here, so that the other people will have better time understanding what you want to achieve.

Notes: The Drupal 7 site builders are used to "Currents user language" checkbox, however that checkbox has been renamed. More information: http://hojtsy.hu/comment/21596#comment-21596

Best regards, Oleg
> 2 votes

---
Tags: views, theming, 8, i18n-l10n
---


# Question
Title: Translation of a field overwrites the original language value
I have encountered a problem with translation. When I try to translate a custom field of a custom node type it overwrites the original value.

Here is how it looks like

The custom field

I create a node and enter following information

Then I click Save, the node appears, so far so good.

Next I click

I can see that translation not available now, click `Add`

Then I have the following url link

```
/node/8/translations/add/en/<my language>

```

Enter the following value

Now I have two nodes.

Let go to the original node and see what is the value of the field.

It is the same as it was before, but on the web page, I have two nodes with different translations.

The interesting thing that both of the two nodes in admin panel have the same translation as currently selected language, even if I click the edit button from the `Translate` tab, I need to switch the language via a switcher for example to get the content of a node for the selected language.

And that makes me crazy, I cannot understand what is going on really, how can I edit a translation of a node without changing the language ?

Please help me to solve this problem, I am completely lost with this stuff.

P.S.

Database entries are added correctly I guess

**EDIT**

My detection configuration before

And set it like this now

Logically, I guess the `Interface Language` should be responsible for translating Admin Panel interface and other helper popups that are used for the development purpose. But `Content translation` should be exactly what I am looking for, but when I switch off the Interface Detection and leave it to by default (uncheck session), but check `Session` in the `Content translation` section, my language switcher disappears.

# Answer
I suggest looking and experimenting with the following settings:

admin/config/regional/language/detection

You can also check if the checkbox "Enable interface translation to English" is checked. That may cause this problem. admin/config/regional/language/edit/en

**Question** : One thing didn't become clear for me: "It is the same as it was before, but on the web page, I have two nodes with different translations." - what is the url of the web page. Is it a page constructed with views, panels, or just node/nid ? Regards, Oleg
> 1 votes

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


# Question
Title: Change default date format in input mask: Is it possible?
I adapted the default date formats to the German needs, and I created a new date format for output. This works fine.

For the input, the *Y-m-d* format persists. How do I change this? I've created a content type: "events". I defined a field type of DATE:

In the manage form display I've set its witget to "Date and Time. There's no wheel to define dmY or other.

The result in input mask:

The only thing that works at the moment, is the widget switching to "date as a list" to get german notation.

# Answer
> 2 votes
Assuming the machine name of your content type is "test".

Please navigate to: **admin/structure/types/manage/*test*/form-display**

You should see the following form (with different fields, of course).

In my example, the name of the field is simply "date" . You can change the widget to Select list and then you will see the cog wheel on the right side of the row.

After clicking on it, you shall be able to choose your preferred Date Format.

Hopefully that helps.

Update 1: Regarding Update In my default Drupal installation when I try to add date-based fields, I do have the following 2 options:

* Date
* Timestamp

Option Date I have suboptions, "Date only" or "Date and time"

* If I choose "Date and time" -\> I am able to see the select widget as option.
* If I choose "Date only" -\> I am able to see the select widget as option.

Timestamp I am able to see only Datetime timestamp

As a last thing: Screenshot, showing the different type of fields in Manage form Display:

**Update 2:** It seems the following article has it explained how to do the exact thing you are looking for: https://www.previousnext.com.au/blog/making-drupal-8-datetime-widgets-use-human-formats

---
Tags: 8, datetime
---


# Question
Title: How do I create a view that shows the results of a content type related to the current page?
I have two content types on my site: "mountains" and "trip reports" with the idea being that users can create a trip report for any particular mountain they have visited.

My "trip reports" content type uses an entity reference field so that the user can select from the list of "mountains" content type.

I want to create a view to display as a block on the "mountains" pages that lists the recent trip reports associated with that mountain. How do I structure my filter in Views? I can either get all trip reports to show up (i.e. trip reports associated with *all* mountains, or none to show up!

Here's my current view setup:

Fields:

* Content: Title

Filter Criteria:

* Content: Published (Yes)
* Content: Type (= Trip Report)

Contextual Filters:

* Content: Title

Relationships:

* Entity Reference: Referencing entity

# Answer
You need to include a Node ID contextual filter as well that is set to Content ID from URL. Then make sure that each of the Fields are set to relate to the relationship entity reference field you are using. I'll try to explain below.

Adding a **Contextual Filter** that looks for the **Content ID from URL** is required as the view will use the found nodeID and use that to know what node it should relate it's fields and relationships too.

You will then want to add a Relationship field that is the Entity Reference field that creates the relationship between the Trips (children) and the Mountain (parent).

Now with the fields, if you just add fields and do not modify any settings, the view will only display content that is available in the original node. For instance, adding the Title field will display the title of the Mountain and not the title of the Trip reports. This is because it doesn't know it should get the information from anywhere else, even though we added the Relationship field before.

This is why you need to modify the fields and set their Relationship to the Entity Reference field. This will now tell the view that even though we are on the Mountain node and have it's ID, the fields are going to output the content related to the entity that is referenced by the nid in the contextual filter.
> 0 votes

---
Tags: views
---


title: Configure NGINX on Centos 6.8

text:
# Question
Title: Configure NGINX on Centos 6.8
I have nginx installed on our server and configured with a previous drupal 7 installation and it works well.

I have installed a new drupal 7 installation and i want to configure it to also work with NGINX already installed on the server. Is there a configuration file i have to update? Please someone point me to the right direction.

This new site is running on the same server but a different cpanel with the previous site.

# Answer
You need to create a new Server Block for the new domain.

This is the file that NGINX reads in order to determine where it will look for the site when a request for a domain come through.

The configuration will be under

```
/etc/nginx

```

The relevant/current entry could be in `nginx.conf`, in a file under `conf.d` or `sites-available`.
> 0 votes

---
Tags: 7
---


# Question
Title: How do I add a meta tag when creating a node via REST API?
So I have this code, using Guzzle POSTing to create node via Drupal REST API. No error, but the `field_meta_tags` value is empty on the node created (still using default `[node:summary]` for the meta description).

```
$node = array(
'title' => array(0 => array('value' => 'asd')),
'type' => array(0 => array('target_id' => 'page')),
'path' => array(0 => array('alias' => $pathalias)),
'field_meta_tags' => array(
  'title' => 'asd',
  'description' => 'asd',
  'keywords' => 'asd',
),
'body' => array(0 => array('value' => 'huehuehue')),
);

$response = $client->post($base_url . '/entity/node', array(
  'cookies' => $jar,
  'query' => array(
    '_format' => 'json',
  ),
  'headers' => array(
    'Accept' => 'application/json',
    'Content-Type' => 'application/json',
    'X-CSRF-Token' => $csrf_token,
  ),
  'json' => $node
));

```

I also try using array structure like this:

```
'field_meta_tags' => array(0 => array(
  'title' => 'asd',
  'description' => 'asd',
  'keywords' => 'asd,
)),

```

But still no luck.

What is the correct format to provide metatag value? Or is there another thing that I might need to check?

# Answer
> 3 votes
I copy/paste the following snippets from the readme file of the metatag module. I can see that you are missing the serialize function in your solution. Hopefully that helps you.

```
Programmatically assign meta tags to an entity
--------------------------------------------------------------------------------
There are two ways to assign an entity's meta tags in custom module. Both
scenarios require a "Metatag" field be added to the entity's field settings, the
field name "field_meta_tags" is used but this is completely arbitrary.

Option 1:

  $entity_type = 'node';
  $values = [
    'nid' => NULL,
    'type' => 'article',
    'title' => 'Testing metatag creation',
    'uid' => 1,
    'status' => TRUE,
    'field_meta_tags' => serialize([
      'title' => 'Some title',
      'description' => 'Some description.',
      'keywords' => 'Some,Keywords',
    ]),
  ];
  $node = \Drupal::entityTypeManager()->getStorage($entity_type)->create($values);
  $node->save();

Option 2:

  $node = Node::create(array(
    'type' => article,
    'langcode' => 'en',
    'status' => 1,
    'uid' => 1,
  ));
  $node->set('title', 'Testing metatag creation');
  $node->set('field_meta_tags', serialize([
    'title' => 'Some title',
    'description' => 'Some description.',
    'keywords' => 'Some,Keywords',
  ]));
  $node->save();

In both examples, the custom meta tag values will still be merged with the
values defined via the global defaults prior to being output - it is not
necessary to copy each value to the new record.

```

---
Tags: 8, meta-tags
---


# Question
Title: Modifying default workbench view filter via code
Workbench ships the 'My Content' view default in code. I want it to actually show "my content" by adding a contextual filter with the author by field = current user.

I've looked into http://blog.arvixe.com/altering-default-views-in-code/, but it is a drupal 7 implementation and doesn't touch on the filtering.

# Answer
> 0 votes
The preferred approach to do those things in Drupal 7 is to:

1. Clone "My content" view to "My content clone view".
2. Make modifications to "My content clone view"
3. Disable "My content" (the original view).

I still haven't tried this in Drupal 8, but I think the principle should be the same.

Regards, Oleg

---
Tags: views, 8
---


# Question
Title: How to replace login in "to" mail field?
In registration notify email, or in emails sending by rules f.e., there is a prefix contained login of recipient in field "to". How can i change it for custom field value? P.S. I use MimeMail module, if it matters.

# Answer
> 0 votes
I just had to fill 'to' field in a format 'custom name ', instead 'address@mail.com'.

---
Tags: emails
---


# Question
Title: query to fetch all path aliases's content type and title
I want to know the titles and content types of all the aliases given in table `url_alias` . For this, I'm writing query :

```
$connection = \Drupal::database();
    $query = $connection->select('node_field_data', 'n');
    $query->join('url_alias', 'u', '/node/n.nid = u.source');
    $result = $query->fields('n', ['changed', 'nid','type'])
                    ->fields('u', ['alias'])
              //->condition('n.type',$content_type, '=')
              //->orderBy('n.title', 'ASC')
              ->execute();

    foreach ($result as $rows) {
        $totalRows[] = $rows;

      }

```

But query is not giving the desired result. What's wrong with the query?

# Answer
> 1 votes
Can you try:

```
$connection = \Drupal::database();
$query = $connection->select('node_field_data', 'n');
$query->leftJoin('url_alias', 'u', 'n.nid = u.source');
$result = $query->fields('n', ['changed', 'nid', 'type']);
$result->addField('u', ['alias']);

$result->execute();

foreach ($result as $rows) {
  $totalRows[] = $rows;
}

```

I saw two main problems.

1) Basically you had a mistake that was causing runtime error:

```
$query->join('url_alias', 'u', '/node/n.nid = u.source');

```

2) Using join, where for this you need left join.

**Different types of joins:** https://stackoverflow.com/questions/5706437/whats-the-difference-between-inner-join-left-join-right-join-and-full-join

**Tip**: Before running $result-\>execute(), you can run $string = $result-\>\__toString(). This will give you the produced raw SQL. You can use it in a tool like adminer/phpmyadmin to debug in more detail.

Best regards, Oleg

---
Tags: 8, path-aliases
---


# Question
Title: A database error is thrown, but mysql works
I am using Drupal 7.54, Drush version 8.1.10, and MySQL version 5.7.17 on Ubuntu 16.04. I mainly use drush for `drush up` to make sure my packages don't get too old.

Last week, everything was working. Today, everything is still working on the website, and I can use `mysql -h localhost --user bar baz -p` (with the same info from the settings file) to log in successfully. However, today, when I tried to run `drush up`, it gave me an error:

> Command pm-update needs a higher bootstrap level to run - you will need to invoke drush from a more \[error\] functional Drupal environment to run this command. The drush command 'up' could not be executed. \[error\] Drush was not able to start (bootstrap) the Drupal database. \[error\] Hint: This may occur when Drush is trying to: * bootstrap a site that has not been installed or does not have a configured database. In this case you can select another site with a working database setup by specifying the URI to use with the --uri parameter on the command line. See `drush topic docs-aliases` for details. * connect the database through a socket. The socket file may be wrong or the php-cli may have no access to it in a jailed shell. See http://drupal.org/node/1428638 for details.

When I run `drush up --debug`, the only additional piece of information is this error:

```
Executing: mysql --defaults-extra-file=/tmp/drush_abc123 --database=obfuscated --host=localhost --silent  < /tmp/drush_def456
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

```

That makes it look like drush is trying to log in as root rather than as the user specified in the settings file, which is weird.

Between last week and this week, I **did** mess around with the database for an unrelated reason, so I'm sure I just messed something up there.

I tried rebooting the machine and restarting the MySQL service, and that didn't change anything. I tried changing from `localhost` to `127.0.0.1` per the drupal.org suggestion, but that didn't change anything. `drush status` **is** pointing to the correct database even though the debug log makes it seem like it isn't.

# Answer
> 1 votes
It turns out, the issue was related to a bug in Drush. https://github.com/drush-ops/drush/issues/2183 discusses an error where a `~/.my.cnf` file will interfere with Drush's database connection.

I didn't have a `~/.my.cnf`, but I did have a `~/.mylogin.cnf`. When I moved that file, everything started working again.

---
Tags: drush
---


# Question
Title: How to configure access for creating a custom LMS?
I am looking to create a LMS either in an existing Drupal install.

Anonymous users can browse course information and also preview certain Modules & Slides (see below). They will be able to buy access to a Course and then view the all the Course content. There will be a multiple different Courses, each need to be purchased separately at different prices.

Course hierarchy:

* Course \> Module(s) \> Topic(s) \> Slide(s)
* Course is what the user will pay for access
* Modules and Topics are the only for categorisation and may only have a Small description
* Preview content will be by only a select few Modules per Course - being able to see the slides within chosen module
* Slides are where the learning content is - mostly videos and PDFs
* Slides may also be a Quiz

Once purchased, the display of the course content will be with the full course hierarchy in a sidebar so the user can navigate through the course and view the content of each slide in the main content panel by selecting the Slide.

**Question**: There are a few choices out there, however I have seen posts about Organic groups. Is this the best way to categorise the Course Content, or should I use `Taxonomy`? (As the how user view the course information will be with the full Course hierarchy in a side bar and selecting Slides will show the Slide content in the main section)

I am very familiar with Drupal basics, but I would like to know how to restrict user access to only their own purchased content?

What would be your solution to set this up?

# Answer
I recommend you have a look at the Group module, which may be considered as a possible alternative to the Organic Groups module, and which you seem to be familiar with already.

Have a look at my answer to "What are the features of the Group module versus Organic Group module?" for details about:

* How both modules compare to each other.
* Integration with various modules that you might want to take advantage of also.

# Resources

# Sample configuration

Below is an example of a possible configuration, which may help to get you started with possible configurations (using the Group module):

```
Group type ID ! Group type ! Group role ID ! Role
--------------+------------+---------------+------------
 1            ! Class      ! 3             ! Instructor
 1            ! Class      ! 4             ! Student
 2            ! Customers  ! 5             ! Lead
 2            ! Customers  ! 6             ! Prospect
 2            ! Customers  ! 7             ! Licensed Customer
 2            ! Customers  ! 8             ! Sales
 2            ! Customers  ! 9             ! Support
 2            ! Customers  ! 10            ! Accounting
 2            ! Customers  ! 11            ! R&D
 3            ! Project    ! 12            ! Project Manager
 3            ! Project    ! 13            ! Developer
 3            ! Project    ! 14            ! Customer

```

### Group Types

The above example consists of 3 ***group types***:

* Class.
* Customers.
* Project.

### Group Roles

For each of the 3 group types, there are specific ***Roles*** defined, some more details about some of them:

* for the *Class* group, these are the 2 roles that are configured:
    + Instructor.
    + Student.
* for the *Project* group, these are the 3 roles that are configured:
    + Project Manager.
    + Developer.
    + Customer.

These are the *Group Specific Roles*: these roles can be configured per group type and will only be available on groups of that group type. As an example, for group type "*Class*", the defined roles are **Instructor** and **Student** (which are not available for the other group types.

On top of the group specific roles, there are also *Special Global Roles*: These are the special (hardcoded) roles named **Outsider** (= a signed in user that did not join a group) and **Member** (= a signed in user that did join a group). These cannot be defined by the Drupal administrator, and they are always available for any group. These roles can have different permissions sets for each group type. Special case: the role **Anonymous** is related to a user that is not signed.

### Groups

Each of the configured group types can have any number of ***Groups***.

Examples of groups:

* for the *Class* group type, there could be these **Groups**:
    + Getting started with Drupal.
    + Drupal for site builders.
    + Become an expert in using the Rules module.
* for the *Customers* group type, there could be these **Groups**:
    + Service Requests.
    + Order Processing.
    + Sales Orders.
    + Relationship Management.

### Permissions

For each of the configured group types, you can then also configure for each ***Content Type*** which ***Role*** has what kind of access (= none, view, create, edit, delete). Be aware: even though this looks similar to Drupal's permission configuration, these permissions are not the same permissions (they are specific to the Group module).

**PS**: this answer applies to either D7 or D8.
> 0 votes

---
Tags: taxonomy-terms, organic-groups
---


# Question
Title: Why is my site's homepage loading in static mode?
I am using the AdvAgg module and all of its submodules, configured it using the configuration in AdvAgg README file.

After doing so, the site's mobile view got problem. So I disabled all from AdvAgg one by one to see what really caused the problem but haven't found one. Note that I was clearing my cache every time when I edited or did something. I then tried to totally uninstall eveything, including CSS and JS files from AdvAgg. But when I went to homepage there's no style at all. I checked the other pages but it looks normal to me. Also mobile view is back to normal.

I checked the source code for homepage and it is using an old CSS file which is produced by AdvAgg (`sites/default/files/advagg_css/.css`, which BTW is just a shortcut name for the css file since it is very long). That directory doesn't exist anymore since I already uninstalled AdvAgg. I enabled and configured AdvAgg again hoping everything will go back to normal but homepage still no style. My conclusion is homepage is loading in static mode.

Homepage was assigned to a certain page so I edited it but nothing's change in homepage. I decided to just copy the style from other pages, rename it to the one used by homepage and then upload it through ftp to the same location pointed by home's css.

Now, the site is back to normal but it is loading in static mode. How am I suppose to change it? Is there anything I've done wrong? I also have an error in status report regarding AdvAgg's HTTP request for js files not getting though. By the way, this is the site www.growplants.org. It is supposed to be the same with this page www.growplants.org/grow-plants as it is assigned to homepage.

# Answer
> 1 votes
I was able to solved this problem by updating drupal core to latest version. If you were able to encounter problem like this and you have the latest version of drupal try to downgrade it to replace corrupted core files and update it again to latest version. I don't know what really caused the problem but this will solve the problem. Just run `drush pm-update` in your drush and it will update all modules and drupal core latest releases. If you only want to update drupal core run `drush up drupal`. If you want to downgrade drupal add the version `drush up drupal-7.x`.

---
Tags: css-js-aggregation
---


title: How to access to node on form_submit

text:
# Question
Title: How to access to node on form_submit
I added a button to the page. I'm trying to get the values of the field when I click the button. But I can not understand how to access the node from submit? Am I on the right track or should I look for another solution? I tried to add $node to the function redirect\_button\_form\_submit but this does not work.

```
function show_on_map_node_view($node, $view_mode, $langcode) {
    $url = url(current_path(), array('absolute' => TRUE));
  if (($node->type == 'addproblem') && (strpos($url, "problem"))) {
    $form = drupal_get_form('redirect_button_form');
    $node->content['redirect_button'] = $form;
 }
}

function redirect_button_form($form, &$form_submit) {
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Show on map'),
    );
    return $form;
}

function redirect_button_form_submit($form, &$form_state) {
//How to access the $node here?

    $geofield = field_get_items('node', $node, 'field_location_exif');
    $location = array(lat => $geofield[0][lat], lon => $geofield[0][lon]);
    $path = '<front>';
    $options = array('query' => $location);
    drupal_goto($path, $options);
}

```

# Answer
You can pass the node as an argument to your form builder and store it there.

```
$form = drupal_get_form('redirect_button_form', $node);

function redirect_button_form($form, &$form_state, $node) {
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Show on map'),
    );

    return $form;
}

function redirect_button_form_submit($form, &$form_state) {
    $node = $form_state['build_info']['args'][0];

    $geofield = field_get_items('node', $node, 'field_location_exif');
    $location = array(lat => $geofield[0][lat], lon => $geofield[0][lon]);
    $path = '<front>';
    $options = array('query' => $location);
    drupal_goto($path, $options);
}

```

drupal\_get\_form can take additional arguments besides $form\_id.

> Any additional arguments are passed on to the functions called by drupal\_get\_form(), including the unique form constructor function. For example, the node\_edit form requires that a node object is passed in here when it is called.

Also, to do a form redirect you can use:

`$form_state['redirect'] = path...`

Instead of drupal\_goto which should not be used here.

> When $form\_state\['redirect'\] is an array it should be populated with arguments appropriate for drupal\_goto() - which is to say, the second element in the array can itself be an array holding all the properties expected by url()'s $options argument, including fragment, query, absolute, etc.
> 2 votes

---
Tags: 7, nodes, forms
---