title: Drupal 8 Custom Migration

text:
# Question
Title: Drupal 8 Custom Migration
We are trying to do migration of joomla database to drupal 8. We are using migrate and migrate plus modules to accomplish this task. We took migrate example module(beer migration) which came with migrate plus module as reference and trying to customize it according to our requirements. But when we try using our custom migration names instead of beer\_term the migrations are not registering. Is there a way that we can register them.

# Answer
There are several things to check for when troubleshooting migrate/migrate plus.

Based on "not registering" make sure you set `id: my_migration` instead of `id: beer_term` or it won't show up when you run `drush ms`. That's the easy one, hopefully it's that. If not...

Failures resulting from errors in your migration configs will be silent most of the time. When they're not silent, they tend to send you on a wild goose chase for something pretty unrelated to what failed. This can make it frustrating to pinpoint what went wrong. Quadruple check your .yml syntax.

Secondly, make sure your config (.yml) files are named correctly. They should be named and placed *exactly* like `/drupal/modules/custom/my_module/config/install/migrate_plus.migration.my_migration.yml` The config files should **NOT** be named `my_module.migration.my_migration.yml`. As @mike ryan points out, resist the temptation to do so.

If you've done all of the above after uninstalling and reinstalling your module, your migration *should* show up when you do a migrate status check.
> 2 votes

---
Tags: 8, migrations
---


# Question
Title: Is there a hook for custom line item before rules price calculation?
I have a complex calculation for item price in a custom line item that I'd like to keep in code rather than rules. Is there a hook that gets called before cart calculation so I can set unit price?

Where is cart pricing calculation done in commerce? trying to find where it's run in source.

Drupal 7 (using kickstart 2)

# Answer
> 1 votes
As Clive mentioned, there's hook\_commerce\_product\_calculate\_sell\_price\_line\_item\_alter() that lets you manipulate the line item prior to the sell price calculation process executing on it. However, whatever unit price you set via that hook may be overridden by Rules that you weren't intending to apply to those line items. In my opinion, the best thing to do would be to write a custom Rules action to encapsulate your pricing and call it in a sell price calculation rule.

---
Tags: commerce, hooks
---


# Question
Title: Drupal 8: Performance Impact of frequently clearing all caches
I have a relatively large production site that uses some custom views to filter by taxonomys and other factors through dropdowns. I have come across the issue that adding a new taxonomy does not allow it to appear in these dropdowns until the cache has been cleared.

I have had a read around and it seems like the most specific thing to do would be to locate the cache tags for these views and invalidate them on creation of a new taxonomy term. However this could be quite complex for me and I was hoping there would be something like `cache_clear_all('*', 'cache_view', TRUE);` from Drupal 7 so I could just rebuild by views cache when in a hook but this doesn't seem to be the case.

I have come across the D8 `drupal_flush_all_caches()` method however this appears to clear and rebuild ALL caches with no options to limit its effect. My first question is, what would be the performance effect on my site if I used `hook_cron` to flush all caches every ~3 hours? Would it be noticeable for the users?

Also, if anyone has a D8 method for clearing specific caches for views/custom blocks etc. I would love to hear them?

# Answer
You can clear the cache tags of a specific view whenever a term is created.

```
function hook_taxonomy_term_insert(EntityInterface $term) {
  if ($term->bundle() == 'VOCABULARY_ID') {
    Cache::invalidateTags(Views::load('view_name')->getCacheTags());
  }
}

```
> 2 votes

---
Tags: views, 8, caching, performance
---


# Question
Title: View all nodes of a content type using a filter
I have a content type called "Building", which contains a field called "Size". I also have an exposed filter that filters through the size chosen by the user, so the view only displays that size.

What I would like is that the view sorts and displays all the nodes in order of relevancy, i.e. if I choose 5-10 meters, the 5-10 meter buildings show up first, and then the rest of the buildings are also shown.

Thanks, and please feel free to comment critically on this post so I can improve on my questions for the future.

# Answer
> 0 votes
In this case, if you are providing a contextual filter, the view will render the filtered out result. However, as I understand from your question, you need the entire nodes of that content type with the contextual filter values on the top.

For this you can try using hook\_views\_post\_execute() where the pre\_render() function is yet not called and sort manually. Or, you can use hook\_views\_pre\_render() function to shuffle the result. At this point, you have all the nodes and you can sort them manually. Hope this is helpful. Thanks

---
Tags: 7, views
---


# Question
Title: Get radio field value in data selector in rules
In content type form, I have a select list as radio with two values "Complaint" and "Feedback".

After content type save, I need to send email if "Complaint" is checked to complaint@web.com and if "Feedback" is checked then send email to feedback@web.com

I know how to do that with text field (e.g **field-text-field** is empty or not) but not yet found any solution with radio buttons.

Note: I have installed the Rules module, and also enabled its sub-modules **Rules UI** and **Rules Scheduler**.

# Answer
> 2 votes
### Step 1

To get your rule to work like you want it to work, for the "Complaint"-part you should use these Rules Conditions (in the specified order):

* ***Entity has field***, for your "select list" field.
* ***List contains item***, whereas:
    + the list is also about that same "select list" field.
    + the item you want to check for (if it is contained in the list) is "`Complaint`".

With those 2 Rules Conditions, your Rules Action to be performed is to send the eMail to complaint@web.com.

For an example Rule (in rules export format) in which you can see this at work, refer to the answer to "How to check for product taxonomy term in Rules actions (Ubercart)". In that case it's about a list of taxonomy terms, but the idea is the same.

### Step 2

Create a similar rule by reepeating Step 1, but now for "Feedback".

### Step 3 (optional)

If you'd be willing to also use the Conditional Rules module, you could merge the rules from Step 1 and 2 in a single rule, ie because this module allows you to include Rules Conditions as part of Rules Actions.

# Answer
> 0 votes
If you want to do this writing a custom code here is one solution: while saving the node call a submit function

```
$form['#submit'] = 'your function';

```

Check the value of the radio button and provide the $to parameter accordingly. then use the snippet below to send the custom email through your module

```
$module = 'module_name';
$key = 'key for the email';
$to = 'mailaddress';// which you set above according to the selected radio value
$language = language_default();
$from = 'from_email_address';
$send = FALSE;
$subject = 'subject line';
$body = 'body of the email';
$params = array(
'subject' => $subject,
'body' => $body,
);
$message = drupal_mail($module, $key, $to, $language, $params, $from, $send);
$message['subject'] = $subject;
$message['body'] = array();
$message['body'][] = $body;
// Retrieve the responsible implementation for this message.
$system = drupal_mail_system($module, $key);
// Format the message body.
$message = $system->format($message);
// Send e-mail.
$message['result'] = $system->mail($message);
if ($message['result'] == 1) {
drupal_set_message(t('Mail has been sent to the user'), 'status');
}
else {
drupal_set_message(t('Mail was not sent'), 'error');
};

```

---
Tags: 7, rules
---


# Question
Title: Is it possible to restore a deleted node?
While revisions are kept and it is easy to get back to a previous revision of a node, I was wondering if it is possible to restore a node that has really been deleted by a user?

# Answer
If you have a database backup (which you should ;) you can restore an old copy of the site and retrieve it that way.

Drupal does give users quite a clear warning that deleting a node is final, and there is a confirmation dialog.
> 21 votes

# Answer
What Chris says. The code reads

```
    db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
    db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);

```

...so deleted really means deleted.

To prevent accidents like this, you may want to restrict user permissions so users cannot delete, but only unpublish nodes. Unpublished nodes will not show up on your site (assuming that your site is built correctly) but they remain available in the database.
> 19 votes

# Answer
Yes there are several solutions for this.

* The first one is using full backups which has already been mentioned by Chris here. this is the most difficult one specially if the node contains complex fields.
* Using https://drupal.org/project/recover module, which monitors
* Using https://drupal.org/project/entity\_soft\_delete module. It created sort of a recycle/trashbin for nodes/entities so when a particular node gets deleted, it won't be removed from the database only its status changes to deleted. So the admin can still see or even use it and if required change its status back to normal or delete it permanently
> 2 votes

# Answer
Here is a suggestion building on what Chris said that reverse engineers @marcvangend's answer. I like to use phpMyAdmin, but you can do this same process with the command line if you like that better.

Like the other answers, this assumes you have a backup of your database. No excuse not to with awesome modules like Backup & Migrate out there.

1. Create a new empty MySQL database called "restore" or "testing" or something similar
2. Create a new manual backup so you can revert to this moment, not last night's backup if you need to
3. Import your backup into the new "restore" database
4. Go to the `node` table, search for your deleted node. Hopefully you know the nid, but if you don't figure it out now.
5. Select the one row that was deleted and export via phpMyAdmin. There should be just one row.
6. Now go to the `node_revisions` table. Search on the nid of your deleted node and export. There should be at least one row, but could be more. Export everything with your nid.
7. Go back to your live site's database in phpMyadmin
8. Import the two files you just exported from the backup
9. Check your work on the live site

Using this method will allow you to restore the single node from the backup without loosing any changes to the database since the last backup. If you're not concerned about that and you don't think anything but the deletion has happened since the last backup, it would be easier to just do a full restore of the last backup that to undergo the process above.
> 0 votes

# Answer
I am.late , but answer is use entity backup module https://www.drupal.org/project/entity\_backup
> 0 votes

---
Tags: nodes, database
---


title: add popups window with link

text:
# Question
Title: add popups window with link
I want to build popups in Drupal 8. This is the code I am using.

```
$attr = array(
 'attributes' => [
   'class' => ['use-ajax'],
   'data-dialog-type' => 'modal',
   'data-dialog-options' => Json::encode([
     'width' => 700,
   ]),
 ]
);
$url = Url::fromRoute('resume.grade_detail', ['uid' => $id, 'courseid' => $courseid]);
$internal_link = \Drupal::l($average, $url, $attr);

return array('#markup => $internal_link);

```

In the rendered output, i don't find the CSS classes I added; as result, the popup doesn't work.

I need help.

# Answer
The markup element strips some HTML tags from the output. It is much better to just use the following code.

```
$attr = [
 'attributes' => [
   'class' => ['use-ajax'],
   'data-dialog-type' => 'modal',
   'data-dialog-options' => Json::encode([
     'width' => 700,
   ]),
 ]
];
$link = Link::createFromRoute($average, 'resume.grade_detail', ['uid' => $id, 'courseid' => $courseid], $attr);

return $link->toRenderable();

```
> 3 votes

---
Tags: navigation
---


# Question
Title: How do I add an ajax item on the submit button?
I created a form using the module "Webform". Now I want to add an #ajax item to the submit button.

Here's what I already did:

```
use \Drupal\Core\Form\FormStateInterface;

function mytheme_form_alter(&$form, FormStateInterface $form_state, $form_id)
{
  $form['#submit']['#ajax'] = array(
    'callback' => '\Drupal\mymodule\Controller\DefaultController::process_form_submission'
  );
}

```

The '#submit' field of the form now looks like this:

```
'#submit' => array(2)
    '0' => string(12) "::submitForm"
    '#ajax' => array(1)
        'callback' => string(72) "\Drupal\mymodule\Controller\DefaultController::process_form_submission"

```

But the `process_form_submission` function is not called. Instead the page reloads on submit as before.

# Answer
**Try this:**

```
$form['actions']['submit']['#ajax'] = array(
        'callback' => '\Drupal\mymodule\Controller\DefaultController::process_form_submission',
'event' => 'click',
      );

```
> 1 votes

---
Tags: ajax, webforms
---


title: Is there a way to minify HTML?

text:
# Question
Title: Is there a way to minify HTML?
Is there a way to minify HTML in Drupal 8, something like the Minify module which is for Drupal 7?

# Answer
> 4 votes
Use spaceless tag. This will not minify the HTML, instead avoids extra whitespace between HTML tags to avoid browser rendering quirks. When cached, can serve better.

In **html.html.twig**

```
{% spaceless %}

<!DOCTYPE html>
<html{{ html_attributes }}>
 #rest of the code
</html>

{% endspaceless %}

```

For compression there is a twig extension

**Edit**: Use Minify Source HTML module which comes for both D7 and D8.

# Answer
> 0 votes
The Advanced CSS/JS Aggregation module has a minify feature:

> CSS/JS Compress Submodules. Can minifiy files & inline CSS/JS. Can also turn off core CSS compression for theme development.

---
Tags: performance
---


# Question
Title: Drupal 7 and CSS - How to have a default style for links without affecting other css styles?
I'm theming a Drupal 7 website using Bootstrap and a sub theme that I have put together. I have used CSS to design some of the menus. For this I have included code in the overrides file so as not to hack the original Bootstrap file.

Here's an excerpt from the CSS file to customize the look of a menu.

`#block-menu-office li {
 display: inline;
 list-style-type: none;
 padding-right: 20px;
 font-size: 1.1em;
 font-style: bold;
 text-decoration: none;
 text-transform: uppercase;
 padding-right: 0.1em;
 padding-top: 0.1em;
}`

This works well.

Now I want to customize how links on the website look like. For some reason they seem to be black with no underline. I want them blue with an underline.

When I add this code, the links do turn blue and show up with an underline. However the menu items also get underlined.

`a:link {
 color: red;
}`

How do I alter the default appearance of the links without affecting how the menu items look? I added a class to the CSS and used this class in the CKEditor when adding the link to the node. However this seems tedious. I would prefer to have a default appearance or alternatively a default class assigned to each link within the node when it is being created. Thanks!

# Answer
> 0 votes
First, I would expect that the styling of menu links by Bootstrap would be more specific than the (general) CSS rules you provide for styling links. But a workaround would be to reapply the styling on the menu links in your sub-theme (with more specific CSS rules).

# Answer
> 0 votes
put your general code first... and add a: link to your menu rule... CSS Cascades... and the more specific you are naming your element the fewer things it touches

---
Tags: theming
---


# Question
Title: How to create a page showing only articles in a certain language?
I have several articles on my website in different languages. I would like to create a page on which only the articles in a certain language are displayed based on the url.

* Only show articles in english when user is on www.website.com/en/blog
* Only show articles in french when user is on www.website.com/fr/blog

How can I do that? I have Internationalization, Entity and Views.

My language detection/selection settings are, in the order:

1. URL (path prefix)
2. Default
3. User

I have two languages: english (default) and french.

All my articles have the vocabulary "**Blog** (taxonomy) \> **story** (term)"

The only thing is, I'm not very good at using Views so I would need a really "step by step" explanation, because it is not really intuitive to me.

Many thanks for your help!

# Answer
> 0 votes
Use the Internationalizations Views module, which extends the i18n module with multilingual support for views.

Also, to make view results correspond to the language switcher, add a filter for **Content Translation: User's Current Language**, which is the language that an authenticated user has set in the user settings (it is NOT the same as the current browser language or the site language).

**Note**: The Internationalizations Views module only has an **alfa** version for D7, but right now there are over 41K users using this version. Therefor I think "DEV" is not a valid release qualifier for that version anymore, because *+41K users can't be wrong*, right?

PS: I'm assuming this question is about D7.

# Answer
> 0 votes
I finally found the solution, I used the Select translation module to add a new filter to Views. My configuration is as below:

Thank you everyone for your precious help!

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


# Question
Title: CKEditor/TinyMCE does not apper or show up at text fields
My CKeditor was working fine untill it suddenly stopped and does not show tabs on the body fields. I have uninstalled it and installed it again but the problem still persists.I have tried to use Wysiwyg Module and tried TinyMce but they all dont show up the tabs

* drupal 7
    + tinyMCE 4.5.1

I have gone through all the similar questions and solutions and none seem to work. i am stuck for the last 3 days. please help me out

# Answer
just a shot in the dark, but have you checked to make sure your text profiles are still correct? You may have to go in and reselect wysiwyg tools for your profiles.
> 0 votes

# Answer
Found out the problem after turning off all the modules and turning on one by one. seems Responsive blocks module had a conflict with the editors. I don,t know how. Thanks for trying to help out. Asante sana.
> 0 votes

---
Tags: wysiwyg
---


# Question
Title: Change, remove Login block title and local-tasks tabs
I have altered login form, removed fields description like this (mytheme.theme):

```
function mytheme_form_user_login_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {

  if (isset($form['name']) && $form['name']['#type'] == 'textfield') {
    unset($form['name']['#title'], $form['name']['#description']);
  }

  if (isset($form['pass']) && $form['name']['#type'] == 'textfield') {
    unset($form['pass']['#title'], $form['pass']['#description']);
  }

}

```

I want to go further and , remove Login block title and local-tasks (Login, Register, Reset password). How to do this? I could just CSS display none it, but thats sounds not very natural...

# Answer
> 0 votes
You can go ahead with the hook\_form\_alter().

```
function your_custom_module_name_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'user_register_form':
// print the $form and you can see the entire structure of the login form.
//You can then unset or overwrite the elements.
break;
case 'user_login_block':
....
break;
case 'user_login':
....
break;
}
}

```

---
Tags: forms, blocks
---


# Question
Title: Deny node access depending on field value
I'm trying to restrict the access to nodes of type article depending on a field value of the node. When I implement `hook_node_access()` it seems to have no effect on the node.

Even if I try to restrict the whole access it seems to have no effect.

```
function mymodule_node_access($node, $op, $account) {
  $type = $node->getType();
  if ($type == 'article') {
    return AccessResult::isForbidden;
  }
}

```

What's my mistake?

# Answer
> 2 votes
With what user do you check the access, as stated in the docs

> The administrative account (user ID #1) always passes any access check, so this hook is not called in that case. Users with the "bypass node access" permission may always view and edit content through the administrative interface.

***user 1 will always have access ..***

Make sure to check with an anonymous or regular user.

---
Tags: nodes
---


# Question
Title: Calculate the number of days since the creation date of a user account
I would like to calculate the number of days past since a users creation date. This is what I have done so far:

```
$user = \Drupal::currentUser();
$registrationdate = getdate($user->getCreatedTime());
$today = getdate();
$daypast = date_diff($regdate, $today);

```

This results in the following error:

> date\_diff() expects parameter 1 to be DateTimeInterface

How can I solve this and get the number of days past since the users registration date?

# Answer
This depends on what you need to do with it. If you truly just need the number of days, then this will work

```
$user = \Drupal::currentUser();
$created = new \DateTime('@' . $user->getAccount()->getCreatedTime());
$interval = $created->diff(new \DateTime());
$days1 = $interval->d
$days2 = intval($interval->format('%d'));

```

Here `$days1` and `$days2` should give you the same value. See the docs for `\DateTime` and `\DateInterval` for more information.

If you need a nifty string for output purposes, then check out `DateFormatter::formatTimeDiffSince()` and friends:

```
$user = \Drupal::currentUser();
$created = $user->getAccount()->getCreatedTime();
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = \Drupal::service('date.formatter');
$created_since = $date_formatter->formatTimeDiffSince($created);

```

and then `$created_since` will be a string like '7 weeks 2 days'. You can also use the 'Time ago' formatter directly in the entity rendering configuration. The default view for the accounts listing does this.
> 3 votes

---
Tags: users, datetime
---


# Question
Title: Custom date format (instead of %date) for WebForm e-mail title?
I have an webform with e-mails adresses that I want to send notifications to.

I want to make the title of the e-mail as e.g. "new message 2017-03-20".

I have tried with pattern suggested under another field (e-mail body):

```
new message %date

```

But it output the formatted date:

```
new message sunday, march 25, 2017 - 17:54

```

Is there a way to put here date in `yyyy-mm-dd` format without chaning the global date formatting on the website?

I also tried to add something like the pattern that is not listed under field:

```
new message [entity-fetched:field_event_date]

```

but it does not get replaced at all (I get message with that literal title):

```
new message [entity-fetched:field_event_date]

```

# Answer
> 3 votes
Place this code in a custom module:

```
     /* first add a custom date field (mydate), you have to set it's value with rules */
  /* change all capital letters with proper names (in lower case) */
  function YOURMODULE_preprocess_node(&$vars) {
$vars['MYDATE'] =
t('!datetime',
  array('!datetime' => format_date($vars['node']->MYDATE,
    'custom', 'M/d/Y, h:i a')));
}
  /* hide custom field to all users but admin */
function YOURMODULE_form_alter(&$form, &$form_state, $form_id) {
  global $user;
  $uuid = $user->uid;
  /*  check that user is NOT admin (No1) */
    if ($uuid !='1') {
        /* if is user profile form use: if ($form_id == 'user_profile_form')*/
      if ($form_id == 'YOUR_FORM_ID') {
      //dsm($form);
        hide($form['field_MYDATE']);
       }
 }

```

for a diferent format look at: http://php.net/manual/es/function.date.php

having date format correct, go agian and do:

```
new message %mydate

```

---
Tags: 7, webforms, datetime
---


# Question
Title: remove drupal admin menu from actual site
i'm using drupal 7 and i want to hide the admin toolbar from the normal sites. but in the configuration i can only find the option to disable the toolbar completely. what i want is that it is only visible on "mysite.com/admin/" and removed from the actual website.

i found some drupal modules with which you can collapse the toolbar or hide it by pressing the UP key but what i want the complete admin toolbar markup gone on my actual site.

i'm removing all the drupal system css and js anyway (using the template.php file) so even if i wanted the admin toolbar on my sites it would look messed up because of the missing styles and scripts.

any ideas?

# Answer
You can remove the toolbar from the "normal" part of you're site by unsetting its entry in the `$page` array using `hook_page_alter`. You can do this in either a module or a theme.

```
function mymodule_page_alter(&$page) {
  unset($page['page_top']['toolbar']);
}

```
> 10 votes

# Answer
You can use the function `admin_menu_supress()` to remove the admin menu from a specific page. It can be called from almost anywhere.

Reference - https://www.rit.edu/drupal/api/drupal/sites!all!modules!admin\_menu!admin\_menu.module/function/admin\_menu\_suppress/7.43
> 1 votes

# Answer
The admin toolbar is only visible when you log in as admin; for the normal users, this toolbar will not be display.
> 0 votes

---
Tags: 7, theming
---


# Question
Title: Create a view to display all nodes referencing this content
I have 2 content types: *Recipe* and *Product*. In *Recipe*, I have an entity refence field to select a *Product* node used from the *Recipe* node.

In the *Product* node, I want to create a view to list all the recipes using that product. This means a block which lists all the recipes that reference this product.

How can I achieve this in Drupal 8?

# Answer
> 0 votes
I've found my mistake :

In Relationship, I have to select the entity reference field used in Recipe. In contextual, I select NID as usual but I have to use the Relationship I've just created. Then I select Provide default value (ID from url).

I don't need to use this relationship in the Fields I add.

---
Tags: views, entities
---


title: Responsive grid in view layout

text:
# Question
Title: Responsive grid in view layout
I think it's an easy question but I just can't solve it.

I use responsive grid type in view to show a content type named "clinic information",and it is.

I want a row only have two clinics and the five-stars are beside the information(picture,phone number...), not below, how can I make it?

(picture, name, address, phone number, five-stars are clinic information in one content in a grid)

# Answer
The important thing to make this work is the theme that your using; the Views Responsive Grid doesn't do much by itself with regards to styling but it allows you setup you view to apply the appropriate CSS class from your theme to make your display responsive.

You are using the Corporate Clean theme but it's not a truly responsive theme from what I can see from its layout CSS. You can still have that layout that you want for one screen type so that will be what I will show you here.

1. Change your view's format to **Responsive Grid**
2. Next change the settings for the **Responsive Grid** format to have 2 column in horizontal alignment and the class `grid_6` to every column. You can also use `grid_4` if you have a sidebar on your page.
3. Then change the Format's **Show** options to fields.
4. Now in the fields section add all the fields that you want to display. For example, I have the fields title, body and post date.

The next step requires you to add some custom html/css; normally advanced view display formats such as Views Bootstrap would have different options to display your fields. For example, had you been using a Bootstrap based theme the Media Object format would have served you well.

However, since you are using something different, I would recommend you override the out of the fields as follows.

5. Hide all but the last one of your fields by clicking on each field and checking the "Exclude from display option".
6. For the last field override its display by clicking on it and going to the **Rewrite Results** section. In the text box provided add in your custom HTML markup with along your fields using tokens provided by views.
7. In you theme make sure to add proper CSS classes, i.e, in the example HMTL I'm showing you should have the classes `clinic`, `clinic-thumb` and `clinic-details`. These should have the styling in such a ways that the `clinic` class clear floats, the `clinic-thumb` and `clinic-details` classes should have floats and respective widths. Example CSS:

/\**

* .clinic has a clearfix taken from this page \*/

.clinic:before, .clinic:after { content: " "; /\* 1 */ display: table; /* 2 \*/ } .clinic:after { clear: both; } /\**

* For IE 6/7 only \*/ .clinic { \*zoom: 1; }

.clinic-thumb{ width: 35%; padding-right: 5%; float: left; } .clinic-details{ float: left; width: 60%; }

If you followed my example you should get something like this:

Hope this helps!
> 6 votes

# Answer
You need to create CSS rules for the output. To make it responsive and fluid, use percentage value instead of pixel value.

**Grid 3:**

`.views-column {
 float: left;
 width: 31%;
}`

**Grid 4:**

`.views-column {
 float: left;
 width: 24%;
}`

To switch the 4-column and 3-column to 2-column on view port width when it is less than 600px:

`@media screen and (max-width: 600px) {
 /* change Grid 4 to 2-column */
 .views-column {
 width: 48.4%;
 }
 .views-column:nth-of-type(3n+1) {
 margin-left: 2%;
 clear: none;
 }
 .views-column:nth-of-type(2n+1) {
 margin-left: 0;
 clear: left;
 }
 /* change Grid 3 to 2-column */
 .views-column {
 width: 48.4%;
 }
 .views-column:nth-of-type(3n+1) {
 margin-left: 3.2%;
 clear: none;
 }
 .views-column:nth-of-type(2n+1) {
 margin-left: 0;
 clear: left;
 }
}`
> 0 votes

---
Tags: 7, views, theming
---


title: dynamic route not updated

text:
# Question
Title: dynamic route not updated
I have dynamic route: from this example

```
/**
 * @file
 * Contains \Drupal\example\Routing\ExampleRoutes.
 */

namespace Drupal\example\Routing;

use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

/**
 * Defines dynamic routes.
 */
class ExampleRoutes {

public function routes() {
  $route_collection = new RouteCollection();

  $route = new Route(
    // Path to attach this route to:
    '/example',
    // Route defaults:
    array(
      '_controller' => '\Drupal\example\Controller\ExampleController::content',
    '_title' => 'Hello'
  ),
  // Route requirements:
  array(
    '_permission'  => 'access content',
  )
);
// Add the route under the name 'example.content'.
$route_collection->add('example.content', $route);
return $route_collection;
}

}

```

the problem here is: the route is not automatically updated (or accessible) until i clear cache, then it works.

question is: how to make the new created route immediately works? \*i try to avoid clear cache command (which i don't think this is the right solution)

Thanks

# Answer
To update the routes you have to call RouteBuilder::rebuild:

```
\Drupal::service('router.builder')->rebuild();

```

This is not what you want to run very often during normal operation of the site. This can take several seconds. It's also not possible to run more than one update process simultaneously. So routes are in general static, even the dynamic ones.
> 3 votes

---
Tags: 8, routes
---


# Question
Title: How to include fragment (#) in the URL computed by redirect?
I want to redirect the user to an internal path that includes a fragment (the part of the url that is introduced with a #), e.g.:

```
/comment/19#comment-19

```

I know how to build the path without the fragment portion. If `$cid` is the comment id, this will do it:

```
$this->redirect($comment->permalink()->getRouteName(), array('comment' => $cid));

```

But how can I add a fragment to the path?

# Answer
> 3 votes
The fragment is stored in the options of the url, also the cid in the parameters. So you'll find all information you need in the url `permalink()` returns:

```
  $url = $comment->permalink();

  $this->redirect($url->getRouteName(), $url->getRouteParameters(), $url->getOptions());

```

---
Tags: 8, redirection
---


# Question
Title: can't change the value of ONE button (search page SEARCH button)
I have succesfully changed the search button text of the block but can't seem to get to do this on the search page

on the following form\_alter both forms enter it and are set but only `search_block_form` gets affected

```
function MODULE_NAME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if(in_array($form_id,["search_block_form","search_form"])) {
    $form['actions']['submit']['#value'] = "Custom Search Value";
  }
}

```

I have also tried doing it with `function hook_preprocess_input($vars){` and also tried to set the weight of the module to run later than others

```
function MODULE_NAME_install(){
  module_set_weight('MODULE_NAME', 1000);
}

```

but I see no difference I had to resolve this using javascript what am I doing wrong ?

# Answer
> 0 votes
Did not realize the search page is structured different than a block search here is the solution that worked posting for anyone might have the same problem

```
function MODULE_NAME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  if(in_array($form_id,["search_block_form"])) {
    $form['actions']['submit']['#value'] = "Custom Search Value";
  }
  elseif(in_array($form_id,["search_form"])) {
    $form['basic']['submit']['#value'] = "Custom Search Value";
  }
}

```

---
Tags: 8, forms
---


# Question
Title: How to return a specific value when using entity_load?
I want to loop through Paragraph bundles and return a string (image path `uri` string).

I can view the Paragraph arrays as such:

```
foreach ($variables['field_paragraphs'] as $i) {
  $entity = entity_load('paragraphs_item', array($i['value']));
  dpm($entity);
}

```

This returns each Paragraph bundle as an multidimensional array. I want to take the value of each `uri` key and place them in their own array.

To that effect I have tried `$image_path = $entity['ParagraphsItemEntity']['field_image']['und']['0']['uri'];`, but it returns nothing.

I've also tried making a function.

```
  function array_column_recursive(array $haystack, $needle)
    {
        $found = [];
        array_walk_recursive($haystack, function ($value, $key) use (&$found, $needle) {
            if ($key == $needle) {
                $found[] = $value;
            }
        });
        return $found;
    }
    print(array_column_recursive($entity, 'uri')[0]);

```

This gives me an error message.

> Fatal error: Cannot redeclare array\_column\_recursive();

(It doesn't seem to matter what the function is named; it will always have this error.)

Would anyone know how to simply get a value from a multidimensional array in Drupal?

# Answer
OK, here's what I did, after discovering Entity Metadata Wrappers:

```
//FORMATS ARRAY TO SOMETHING EASIER TO HANDLE
$entity_wrapper = entity_metadata_wrapper('paragraphs_item', reset($entity));
//RETURN THE VALUE OF THE IMAGE ARRAY
$image = $entity_wrapper->field_image->value();
//RETURN THE (FULL) URL OF THE IMAGE
$file_url = file_create_url($image['uri']);

```
> 0 votes

---
Tags: entities
---


# Question
Title: Why does The special menu items module break the bootstrap dropdown?
Hi Guys this is my issue on my parent menu item i am using the`<nolink>`shortcode to leave the link blank however in my tree i have 3 items underneath it.

If i add `<nolink>` the menu item becomes wrapped in a span tag with no link and the dropdown does not work. if i give the parent a link the dropdown works but only if i select the parent first.

Is this css or a js issue?

# Answer
> 0 votes
It's because bootstrap is expecting an anchor tag and by default Special Menu Items provides a span tag.

Go to admin/config/system/special\_menu\_items and specify an anchor tag as shown below:

---
Tags: javascript, theming
---


# Question
Title: ?format=json returns 'Not acceptable format: json'
I am trying to set up the REST module for Drupal8.2.7. Install went through without problems.

I tried to follow this documentation page https://www.drupal.org/docs/8/api/restful-web-services-api/restful-web-services-api-overview to set up a simple resource for getting nodes.

I followed the descriptions for 'Drupal 8.2 & Later: ' and created this yml file in the this folder \Drupal\rest\RestResourceConfigInterface

```
id: entity.node
plugin_id: 'entity:node'
granularity: method
configuration:
  GET:
    supported_formats:
      - json
    supported_auth:
      - basic_auth
      - cookie

```

Once that was done I cleared the cache and expected to be able to get node 1 as json using this url:

```
/node/1?_format=json

```

However, all I receive is: {"message":"Not acceptable format: json"}

What am I missing here?

Update: I went to here /admin/config/development/configuration/single/export and exported entity.node

```
uuid: d44c745b-d69b-4893-8f31-b65d0fe80bf0
langcode: en
status: true
dependencies:
  module:
    - basic_auth
    - hal
    - node
  _core:
    default_config_hash: t_jfECmZhJqBOJuSOFn87EOi_TWi-_fRYTuJgd19vgg
  id: entity.node
    plugin_id: 'entity:node'
    granularity: resource
  configuration:
    methods:
      - GET
      - POST
      - PATCH
      - DELETE
    formats:
      - json
      - hal_json
    authentication:
      - basic_auth
    GET:
      supported_formats:
        - json
        - xml
      supported_auth:
        - basic_auth
        - cookie
    POST:
      supported_formats:
        - hal_json
        - json
        - xml
      supported_auth:
        - basic_auth
        - cookie
   DELETE:
     supported_formats:
       - hal_json
       - json
       - xml
  supported_auth:
    - basic_auth
    - cookie
  PATCH:
    supported_formats:
      - hal_json
      - json
      - xml
    supported_auth:
      - basic_auth
      - cookie

```

However, trying to get my node via the mentioned url '/node/1?\_format=json' still returns {"message":"Not acceptable format: json"}

# Answer
> 5 votes
`\Drupal\rest\RestResourceConfigInterface` is a namespace not a directory structure.

Configuration files need to be imported into the active configuration which is stored in the database.

In the case of a single config file:

1. Go to the page `/admin/config/development/configuration/single/import`
2. Under "Configuration type" select "REST resource configuration" In the box
3. At "Paste your configuration here" paste your REST YAML configuration

Configuration can be exported and imported using the config directory, as specified in settings.php with the line `$config_directories['sync'] = 'sites/default/config';`.

To export the current active configuration to files in the `sync` directory use the drush command: `drush config-export`

To import configuration from files in the `sync` directory and overwrite your current active configuration, go to the page `/admin/config/development/configuration`.

Another option is to use the REST UI module to configure your REST services.

---
Tags: 8
---


title: jQuery is not defined

text:
# Question
Title: jQuery is not defined
I just started my project which I haven't touched in a while. I got the most recent develop version of it using git and I up'ed my docker. Once I opened my website I saw, that something is off. Console is saying that "Drupal is not defined" and if I visit pages-\> --any page-- -\> content, the layout is off.

In the console here it says ReferenceError: jQuery is not defined.

What I already tried to do:

* Rebuild my project
* Resave configuration of jQuery update
* Clearing cache (lol)
* Checking if JS is enabled on my browser

Can someone help me out please?

# Answer
For someone who might experience this, for me Minify module was causing this, I think I lacked some configuration to use minified JS, so my localhost couldn't load JS, after disabling Minify module, everything was fine. Not the best solution, but for fast results its okay.

P.S. DON'T FORGET TO ENABLE IT IF YOU TWEAK SOME JS CODE AND EXPORT IT AS FEATURE.
> 0 votes

---
Tags: 7, javascript
---


# Question
Title: CAS username field value to be manually added to the existing user on import?
I installed the CAS module on a Drupal 8 site, and it is working fine. For new users, it auto-registers the user with cas\_username, but I would like to import the cas\_username manually for the existing Drupal 8 user.

I also tried importing users in CSV format; I have been able to add the $account(row\[0\],row), but for the CAS username import, i don't know how to import it, and in which field is stored.

```
'uid' => NULL,
'name' => $username,
'field_first_name' => row[0],
'field_last_name' => $row[1],
'pass' => $username,
'mail' => $row[2],
'status' => 1,
'created' => REQUEST_TIME,
'roles' => array_values($config['roles']),

```

I tried Managing CAS username; the suggestion given is for Drupal 7, but the same method doesn't work for Drupal 8.

How do I import the CAS username in CSV?

# Answer
> 0 votes
I find out the solution for the CAS\_username import in CSV method. The method of db\_insert in (authmap) table, which dynamically insert the CAS\_username in respective field.

The authmap table is present in external authentication module.

```
    db_insert('authmap')
    ->fields(array(
     'uid' => $uid,
     'provider' => 'cas',
     'authname' => $row[0],
     'data' => 'N;',
     ))
    ->execute();

```

So this is the method, i dynamically update the CAS\_username using CSV. If any suggestions or update in that. Kindly Prescribe it.

---
Tags: 8, users, importing-exporting
---


# Question
Title: Determine main menu item on front page updating menu--main.html.twig
I am trying to write a custom twig for menu--main.html.twig under Drupal 8.3. When in the menu\_links macro while on the home page, the item.in\_active\_trail is not TRUE. I tried to compare the path('') to item.url but it never returns true. I can print out both path('') and item.url and see that they output the same exact text (character for character). Is there a special way to determine if the item.url is the front page or to string compare URL strings?

```
{{ path('<front>') == item.url ? 'true' : 'false' }} ==> 'false'
{{ path('<front>') }} ==> '/drupal8_test/'
{{ item.url }} ==> '/drupal8_test/'

```

# Answer
> 2 votes
To get the path from `item.url` you would have to use the method `toString()`:

```
  {{ item.url.tostring }}

```

Instead of comparing strings a better approach might be to check for the route name of the frontpage:

```
  {% if item.url.routed and item.url.routename == '<front>' %}
    <em>Front Page</em>
  {% endif %}

```

---
Tags: theming, 8, navigation
---


# Question
Title: Render values directly in a twig paragraph template
I'm working with the paragraph module and I've created a **paragraph type** called *Image Teaser Block* wich is an **entity reference to a content type** (Image Teaser, multiple references possible). This content type has 5 fields (Image, list, 2x text + link) and I'd like to render the values directly in the paragraphs template (**paragraph--image-teser-block.html.twig**).

What I could do is using **{{content}}** or **{{content.field\_image\_teaser}}** to render the HTML in the paragraph template and then change the **field templates**. But because I have many different paragraph types and each has a lot fields I would end up with **tons of templates** (imagine 10 different paragraphs with 6 fields each -\> 60 different template files) and that's not really efficient to work.

So how can get the **values (not rendered HTML)** in the **paragraph--image-teser-block.html.twig** file like that:

```
<div class="wrapper">
    {% for item in imageTeaserBlock %}
        <article style="background-image: url('{{item.img.url}}');">
            <a href="{{item.link}}">
                <div>{{item.listLabel}}</div>
                <div>
                    <div >{{item.title}}</div>
                    <h2 >{{item.subtitle}}</h2>
                </div>
            </a>
        </article>
    {% endfor %}
</div>

```

I think the same issue applies also to content types wich are entity references to other content types.

# Answer
> 1 votes
I'm new to Drupal also and was trying to do the exact same thing. I simply put the machine name of the input I was trying to show in to the twig template i.e - {{ field\_image\_caption }} - flsuhed the cache and it magically appeared. Hope that helps.

```
<div class="slice h-clearfix">
    <div class="l-col-12 l-content t-content article-content">
        <div class="l-col-10 l-push-1 l-padding">
            <div class="article-image">
                {{ field_image }}
                <div class="article-img-social">
                    <div class="article-caption">
                    PHOTO CREDIT: {{ field_image_caption }}
                    </div>
                <div class="article-img-share share-article-image"></div>
            </div>
        </div>
    </div>
</div>

```

# Answer
> 0 votes
One of the ways to do this is like this.

Collect all the values that you need and set it to a variable, then use that object in your twig template. Below is an example...

```
{%
  set c2a = {
    boxed: paragraph.field_boxed.value,
    component_achtergrond: paragraph.field_component_achtergrond.value|replace({' ': '_'}),
    tekst:content.field_tekst,
    afbeelding:content.field_afbeelding,
    afbeelding_url: file_url(content.field_afbeelding['#items'].entity.uri.value),
    uitlijning_kolommen: paragraph.field_uitlijning_kolommen.value|replace({' ': '_'}),
    breedste_kolom: paragraph.field_breedste_kolom.value|replace({' ': '_'}),
  }
%}

{% set afbeelding_style_background = "style=background-image:url(#{c2a.afbeelding_url});background-size:cover" %}

<div class="component c2a">
  <div class="{{ c2a.boxed ? '' : c2a.component_achtergrond }}">
    <div class="container" {{ c2a.uitlijning_kolommen == 'visual_background' ? afbeelding_style_background}}>
      <div class="{{ c2a.boxed ? 'box ' ~ c2a.component_achtergrond : '' }}">

        <div class="flexbox {{ c2a.breedste_kolom }} {{ c2a.uitlijning_kolommen }}">

          {% if c2a.uitlijning_kolommen != 'visual_background' %}
            <div class="visual">{{ c2a.afbeelding }}</div>
          {% endif %}

          <div class="descriptor">{{ c2a.tekst }}</div>
        </div>

      </div>
    </div>
  </div>
</div>

```

---
Tags: theming, 8
---


# Question
Title: How do I convert a render array to plain HTML?
I have a render array with a list of items.

```
$array = array(
  'list' => array(
    '#items' => $items,
    '#theme' => 'item_list'
  )
);

```

I tried to use it with `ajax_command_html()`, which works perfectly with a simple HTML string, but it doesn't work when it gets a render array.

Can I somehow convert this render array to an HTML string to use it with that function?

# Answer
`ajax_prepare_response()` contains the following code.

```
$html = is_string($page_callback_result) ? $page_callback_result : drupal_render($page_callback_result);
$commands[] = ajax_command_insert(NULL, $html);
// Add the status messages inside the new content's wrapper element, so that
// on subsequent Ajax requests, it is treated as old content.
$commands[] = ajax_command_prepend(NULL, theme('status_messages'));

```

So, to achieve the same (i.e. convert a render array into a HTML string), you can call `drupal_render()` passing the render array to the function.

```
 $render_array = array(
    '#items' => $items,
    '#theme' => 'item_list'
 );

 return ajax_command_html($elector, drupal_render($render_array));

```

Also `theme()` would return a HTML string, and you could as well use the following code.

```
 return ajax_command_html($elector, theme('item_list', array('items' => $items)));

```

Since Drupal 8 doesn't have the `theme()` function anymore, I would use `drupal_render()` just to make easier to convert Drupal 7 code to Drupal 8.

Keep in mind that `drupal_render()` is expecting an array; in the case you are calling it from a function that could receive a string as argument, you need to verify you are passing an array to `drupal_render()`, as the code I shown does.
> 0 votes

---
Tags: 7, ajax
---


title: Programatically define Menu links

text:
# Question
Title: Programatically define Menu links
I want to show **Login** link in the Menu navigation, only for guest User.

```
clinical_trial.login:
  title: Login
  description: 'Login'
  parent: main
  menu_name: main
  route_name: user.login

```

This is my Custom Menu links code.

What to add?

# Answer
If you are creating a menu link from a custom module, you can check this

https://www.drupal.org/docs/8/api/routing-system/structure-of-routes

Quoting the documentation:

```
requirements (required): Determines what must be met in order to grant access to the route.
    _role: A specific Drupal role, eg. 'anonymous'.

```

Alternatively you can use this module: https://www.drupal.org/project/menu\_item\_visibility "It exposes configurable and extendable visibility settings for menu links."
> 0 votes

---
Tags: 8, navigation
---


# Question
Title: Is a node linked in any Panel (Drupal 7)?
Is there a way in Drupal 7 to find out if a specific node is used in any panel of any page?

Would be helpful to prevent my editors from deleting content when it's still needed in some other part of the page.

# Answer
> 6 votes
You are looking for something along the lines of `file_usage_list()` I guess. I also assume that you are interested in the "Add content \> Existing node" functionality of Panels.

You could implement your own function, with the following code:

```
function _panels_node_usage_list() {
  $result = db_query(
    "SELECT * FROM {panels_pane} WHERE type = 'node' AND subtype = 'node'"
  );
  $node_usage_list = array();
  foreach ($result as $pane) {
    $pane_configuration = unserialize($pane->configuration);
    $node_usage_list[$pane_configuration['nid']]++;
  }
  return $node_usage_list;
}

```

and then call this function from your own implementation of `hook_node_access()` where you can check if the nid of the node to be deleted is in the array returned by `_panels_node_usage_list()`.

Good luck!

---
Tags: 7, nodes, panels
---


title: Add content to drupalgap drop down

text:
# Question
Title: Add content to drupalgap drop down
I have recently started working with D7. I made a test page and installed drupal gap to run it with mobile-application. I wants to assigned more nodes to the drop down menu under contents, taxonomy and users but I don't know how get this. I have added a screen shot to make it more clear.

# Answer
> 0 votes
This is the Main Menu section as I see.

You need to made changes "`settings.js`" file present inside **mobile-application\app** folder.

Example:

```
// Main Menu
drupalgap.settings.menus['main_menu'] = {
  options: menu_popup_get_default_options(),
  links: [
    /*
    {
      title:'Content',
      path:'node',
      options:{
        attributes: {
          'data-icon': 'star',
          'class': 'ui-btn ui-btn-icon-right'
        }
      }
    },
    {
      title:'Taxonomy',
      path:'taxonomy/vocabularies',
      options:{
        attributes:{
          'data-icon':'grid'
        }
      }
    },
    {
      title:'Users',
      path:'user-listing',
      options:{
        attributes:{
          'data-icon':'info'
        }
      }
    }
    */
    {
      title:'Home',
      path:'home',
      options:{
        attributes: {
          'data-icon': 'home',
          'class': 'ui-btn ui-btn-icon-right'
        }
      }
    },
    {
      title:'Services',
      path:'websolution',
      options:{
        attributes:{
          'data-icon':'star'
        }
      }
    },
    {
      title:'Our Work',
      path:'ourwork',
      options:{
        attributes:{
          'data-icon':'star'
        }
      }
    },
    {
      title:'About Us',
      path:'articles',
      options:{
        attributes:{
          'data-icon':'star'
        }
      }
    },
    {
      title:'Testimonials',
      path:'testimonial',
      options:{
        attributes:{
          'data-icon':'star'
        }
      }
    },
    {
      title:'Contact',
      path:'node/58',
      options:{
        attributes:{
          'data-icon':'action'
        }
      }
    }

  ]
};

```

You will get details http://docs.drupalgap.org/7/Menus

---
Tags: 7, javascript
---


# Question
Title: Get the fields from a reference entity (content type) in a Paragraph field
I have a paragraph field that is a reference entity to the *Customer Testimonial* content type. A content editor can add the *customer-testimonial* paragraph and type the name of the testimonial. This will then display the text on the website.

I have made a *paragraph--c15a-customer-testimonial.html.twig* template file with the following code.

```
{%
  set c15a = {

    title: content.field_testimonial.entity.field_testimonial_titel,

  }
%}

<div class="component c15a">
    <div>

        <div>Testimonial title</div>

        <h2>{{ c15a.title }}</h2>

    </div>
</div>

```

Of course, this prints nothing. How can I get the fields from the content type I'm referencing in my paragraph?

# Answer
The referenced entity is not built yet, so you can't access the formatted field content.

You can get the field value from the database by using the paragraph object:

```
{{ paragraph.field_testimonial.entity.field_testimonial_titel.value }}

```

This is unformatted, which might work for a title field.

If you want a formatted output better use a custom view mode for the referenced entity to configure the fields, or in this case one field, if this is all you want to display.
> 2 votes

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


title: Emergency message on site with rules(?)

text:
# Question
Title: Emergency message on site with rules(?)
In the event of an emergency I would like the site administrator to push a message to all screens (to any anonymous viewer on any page). The push should not require the visitor to refresh their page or visit another page. The message must push out to all pages without requiring the viewer to take action.

Perhaps after a cron run?

Additional nice-to-haves:

1. the message is a node of a specific content type
2. upon creating this node, the author must "activate" the node before the message is live

Any suggestions?

# Answer
I think this is what you want Rules action with node.js module

In order to do this, you have to install the node.js on your server. They have a tutorial video for that Installation of Node.js integration module for Drupal
> 2 votes

# Answer
Have a look at the Menu Badges module to add such notifications to any **menu item** and/or **menu tab** of your choice.

Here are some details about it (from its project page):

> Provides a method for adding iOS-style badges to menu items. (see screenshot)
>
> ### Adding Badges to Menus
>
> Once enabled, go to `Administration > Structure > Menus`, and click "list links" next to the menu containing the target item. Click "edit" next to the item and select the badge to display with the Display Menu Badge select box.
>
> ### Adding Badges to Tabs
>
> For adding badges to menu tabs, there is a tab under `Administration > Structure > Menus` called "Tab Menu Badges". Search for the menu router path of the tab you want to alter, then select a badge from the corresponding select box.
>
> ### Badge Types
>
> The module includes five example badges, and new badges can be created easily with Views. Modules can also supply their own badges with a hook implementation. See the README.txt file for details.

Because of how it integrates with the Views module, you basically reduce your question/problem to something like "Just create an appropriate view of it" (eg to list a node containing your special message, and a boolean field to "activate" it, as in your extra nice-to-have).

### Video tutorials:
> 0 votes

---
Tags: 7, rules
---


title: 404 and 403 Errors after site migration

text:
# Question
Title: 404 and 403 Errors after site migration
I have migrated a site from one server to another and the page just refuses to work.

I have all modules enabled as on the old server, .htaccess is present in the root folder yet when i access the site through URL i get

```
The requested page could not be found.

```

when i add 'q' param like so: `/?q=user`

I get the user login screen however when i try to log in i get access denied.

apache error logs are clear. The configuration looks like this:

```
<VirtualHost *:80>
        DocumentRoot /var/www/

        <Directory "/var/www/site/">
                Options +Indexes +FollowSymLinks +MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

```

running Apache2.4

.htaccess

```
#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
  Order allow,deny
</FilesMatch>

# Don't show directory listings for URLs which map to a directory.
Options -Indexes

# Follow symbolic links in this directory.
Options +FollowSymLinks

# Make Drupal handle any 404 errors.
#ErrorDocument 404 /index.php

# Force simple error message for requests for non-existent favicon.ico.
<Files favicon.ico>
  # There is no end quote below, for compatibility with Apache 1.3.
  ErrorDocument 404 "The requested file favicon.ico was not found.
</Files>

# Set the default handler.
DirectoryIndex index.php
#DirectoryIndex phpinfo.php
# Override PHP settings. More in sites/default/settings.php
# but the following cannot be changed at runtime.

# PHP 4, Apache 1.
<IfModule mod_php4.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# PHP 4, Apache 2.
<IfModule sapi_apache2.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  <FilesMatch \.php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  </FilesMatch>
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  # adapt and uncomment the following:
  # RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
  # RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
  #
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  # uncomment and adapt the following:
  # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
  # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  # RewriteBase /

  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

```

Tried to access admin sections for clear urls but i get access denied - i just can not access any page really. Not sure if there is anything i can do via DB.

**EDIT:**

This is very interesting find - it turned out that the database encoding was wrong.. So i had to drop the cluster and recreate it with correct encoding (and that meant changing machine locale). The DB encoding was LATIN but its supposed to be UTF-8. After doing so everything works as expected.

# Answer
> 1 votes
Probably this is because clean urls are enabled. After you logged in at ?q=user/login go to ?q=admin/config/search/clean-urls and check if you have clean urls working (you should see a checkbox appear). Otherwise check the following.

* check if rewrite\_module is enabled
* check if .htacces files exists in root dir
* check contents of .htacess for rewriting
* check permission of .htaccess
* check if AllowOverride is set to all. AllowOverride all

---
Tags: .htaccess
---


# Question
Title: Custom module update with project status url
My .info file is the following.

```
name = {some_name}
description = This will contain all {some_name} related information
package = {Package_name}
core = 7.x

; Information added by Drupal.org packaging script on 2014-10-03
version = "7.x-1.1"
core = "7.x"
project = "{project_name}"
project status url=http://domain.com/{project_name}/7.0/sub_module
datestamp = "1432104957"

```

I uploaded the sub\_module.zip and the sub\_module.tar.gz files, as well as the sub\_module folder to the above project status URL, with .info version set to 7.x.2.1.

Still I'm not getting any updates for my custom module. Can anyone help me with this?

# Answer
> 0 votes
The project status URL you provided in the .info file is wrong: It should be http://domain.com, in the same way for Drupal.org that URL is http://updates.drupal.org/. A Drupal site will then access (in your case) `http://domain.com/{project_name}/{drupal_version}` to verify the module needs to be updated.
`http://domain.com/{project_name}/{drupal_version}` needs to return XML data listing all the versions available for that project and that Drupal version.

To make an example with a project hosted on Drupal.org, the list of all the versions available for Drupal 7.x of the Views module is returned from http://updates.drupal.org/release-history/views/7.x, which returns the following XML data.

```
<?xml version="1.0" encoding="utf-8"?>
<project xmlns:dc="http://purl.org/dc/elements/1.1/">
<title>Views</title>
<short_name>views</short_name>
<dc:creator>merlinofchaos</dc:creator>
<type>project_module</type>
<api_version>7.x</api_version>
<recommended_major>3</recommended_major>
<supported_majors>3</supported_majors>
<default_major>3</default_major>
<project_status>published</project_status>
<link>https://www.drupal.org/project/views</link>
<terms><term><name>Projects</name><value>Modules</value></term><term><name>Maintenance status</name><value>Seeking co-maintainer(s)</value></term><term><name>Development status</name><value>Under active development</value></term></terms>
<releases>
<release><name>views 7.x-3.16</name><version>7.x-3.16</version><tag>7.x-3.16</tag><version_major>3</version_major><version_patch>16</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.16</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.16.tar.gz</download_link><date>1491158584</date><mdhash>d840cb148809da844b93d73b16b453f9</mdhash><filesize>1643030</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.16.tar.gz</url><archive_type>tar.gz</archive_type><md5>d840cb148809da844b93d73b16b453f9</md5><size>1643030</size><filedate>1491158584</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.16.zip</url><archive_type>zip</archive_type><md5>58da4a76b03278e613f8298e69f761c6</md5><size>1913513</size><filedate>1491158584</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.16-rc1</name><version>7.x-3.16-rc1</version><tag>7.x-3.16-rc1</tag><version_major>3</version_major><version_patch>16</version_patch><version_extra>rc1</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.16-rc1</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.16-rc1.tar.gz</download_link><date>1489763584</date><mdhash>cba59381dbf64ac9d9d76fa549b4c7c1</mdhash><filesize>1642814</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.16-rc1.tar.gz</url><archive_type>tar.gz</archive_type><md5>cba59381dbf64ac9d9d76fa549b4c7c1</md5><size>1642814</size><filedate>1489763584</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.16-rc1.zip</url><archive_type>zip</archive_type><md5>460ed4581a0a7680fad79e1c124cedc3</md5><size>1913275</size><filedate>1489763584</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security>RC releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.15</name><version>7.x-3.15</version><tag>7.x-3.15</tag><version_major>3</version_major><version_patch>15</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.15</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.15.tar.gz</download_link><date>1487784184</date><mdhash>473cb5384456d55af988feabc1af12ed</mdhash><filesize>1642425</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.15.tar.gz</url><archive_type>tar.gz</archive_type><md5>473cb5384456d55af988feabc1af12ed</md5><size>1642425</size><filedate>1487784184</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.15.zip</url><archive_type>zip</archive_type><md5>d22aa50667d4905a6b954c58d7c29832</md5><size>1913348</size><filedate>1487784184</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.14</name><version>7.x-3.14</version><tag>7.x-3.14</tag><version_major>3</version_major><version_patch>14</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.14</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.14.tar.gz</download_link><date>1466019539</date><mdhash>168bb684c8f34297be94b03c797841e5</mdhash><filesize>1656594</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.14.tar.gz</url><archive_type>tar.gz</archive_type><md5>168bb684c8f34297be94b03c797841e5</md5><size>1656594</size><filedate>1466019539</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.14.zip</url><archive_type>zip</archive_type><md5>b8ee0f4278b2f67e4d10997dc2a05ec4</md5><size>1913123</size><filedate>1466019539</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.13</name><version>7.x-3.13</version><tag>7.x-3.13</tag><version_major>3</version_major><version_patch>13</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.13</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.13.tar.gz</download_link><date>1446804839</date><mdhash>50d3b231f689f8c4ff15d79ea3c261d9</mdhash><filesize>1650157</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.13.tar.gz</url><archive_type>tar.gz</archive_type><md5>50d3b231f689f8c4ff15d79ea3c261d9</md5><size>1650157</size><filedate>1446804839</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.13.zip</url><archive_type>zip</archive_type><md5>d30756ba6b3489fd919ddd359f5decad</md5><size>1900939</size><filedate>1446804839</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.12</name><version>7.x-3.12</version><tag>7.x-3.12</tag><version_major>3</version_major><version_patch>12</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.12</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.12.tar.gz</download_link><date>1446653339</date><mdhash>a50033bb090730176d9263ddae7f32b2</mdhash><filesize>1650130</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.12.tar.gz</url><archive_type>tar.gz</archive_type><md5>a50033bb090730176d9263ddae7f32b2</md5><size>1650130</size><filedate>1446653339</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.12.zip</url><archive_type>zip</archive_type><md5>56beb9d18dcc252ca77834f52b9050d1</md5><size>1900868</size><filedate>1446653339</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.11</name><version>7.x-3.11</version><tag>7.x-3.11</tag><version_major>3</version_major><version_patch>11</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.11</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.11.tar.gz</download_link><date>1430320981</date><mdhash>00d722e1d8ed57e912c8bd586cf2edbe</mdhash><filesize>1649389</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.11.tar.gz</url><archive_type>tar.gz</archive_type><md5>00d722e1d8ed57e912c8bd586cf2edbe</md5><size>1649389</size><filedate>1430320981</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.11.zip</url><archive_type>zip</archive_type><md5>448b10631be9423948f4bad59d269593</md5><size>1899261</size><filedate>1430320981</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.10</name><version>7.x-3.10</version><tag>7.x-3.10</tag><version_major>3</version_major><version_patch>10</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.10</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.10.tar.gz</download_link><date>1423648081</date><mdhash>c9806ffd69448bc505a67e790f97da58</mdhash><filesize>1648314</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.10.tar.gz</url><archive_type>tar.gz</archive_type><md5>c9806ffd69448bc505a67e790f97da58</md5><size>1648314</size><filedate>1423648081</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.10.zip</url><archive_type>zip</archive_type><md5>45246351588a7f9f74a7d8ba1e0554f4</md5><size>1897924</size><filedate>1423648081</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.8</name><version>7.x-3.8</version><tag>7.x-3.8</tag><version_major>3</version_major><version_patch>8</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.8</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.8.tar.gz</download_link><date>1400618927</date><mdhash>0fbe71c455f5d34c7193797563b63b3f</mdhash><filesize>1646817</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.8.tar.gz</url><archive_type>tar.gz</archive_type><md5>0fbe71c455f5d34c7193797563b63b3f</md5><size>1646817</size><filedate>1400618927</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.8.zip</url><archive_type>zip</archive_type><md5>c1a997653b21943a86bcd42f5c803403</md5><size>1886165</size><filedate>1400618927</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term><term><name>Release type</name><value>Bug fixes</value></term><term><name>Release type</name><value>New features</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.7</name><version>7.x-3.7</version><tag>7.x-3.7</tag><version_major>3</version_major><version_patch>7</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.7</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.7.tar.gz</download_link><date>1365499237</date><mdhash>3f36f0d13f3b724d719f6729cbc110ba</mdhash><filesize>1639539</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.7.tar.gz</url><archive_type>tar.gz</archive_type><md5>3f36f0d13f3b724d719f6729cbc110ba</md5><size>1639539</size><filedate>1365499237</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.7.zip</url><archive_type>zip</archive_type><md5>c764bcc139e3698b24f4bfcc531542e4</md5><size>1878608</size><filedate>1365499237</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.6</name><version>7.x-3.6</version><tag>7.x-3.6</tag><version_major>3</version_major><version_patch>6</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.6</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.6.tar.gz</download_link><date>1363810217</date><mdhash>1531a1ece3970332db1559b854f5dcc9</mdhash><filesize>1639219</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.6.tar.gz</url><archive_type>tar.gz</archive_type><md5>1531a1ece3970332db1559b854f5dcc9</md5><size>1639219</size><filedate>1363810217</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.6.zip</url><archive_type>zip</archive_type><md5>0d7c7de301caa52670869060e22d1ef3</md5><size>1878465</size><filedate>1363810217</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.5</name><version>7.x-3.5</version><tag>7.x-3.5</tag><version_major>3</version_major><version_patch>5</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.5</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.5.tar.gz</download_link><date>1345829395</date><mdhash>fba70998d4ebcca5116ef5ee90117738</mdhash><filesize>1632919</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.5.tar.gz</url><archive_type>tar.gz</archive_type><md5>fba70998d4ebcca5116ef5ee90117738</md5><size>1632919</size><filedate>1345829395</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.5.zip</url><archive_type>zip</archive_type><md5>8b1102f6cd54949eee147c63c4fd352b</md5><size>1866348</size><filedate>1345829395</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.4</name><version>7.x-3.4</version><tag>7.x-3.4</tag><version_major>3</version_major><version_patch>4</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.4</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.4.tar.gz</download_link><date>1345559303</date><mdhash>72bd0f35ac467aed74e533c10a76c93f</mdhash><filesize>1632803</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.4.tar.gz</url><archive_type>tar.gz</archive_type><md5>72bd0f35ac467aed74e533c10a76c93f</md5><size>1632803</size><filedate>1345559303</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.4.zip</url><archive_type>zip</archive_type><md5>0e92dc862bea87904d507af72e710af7</md5><size>1866193</size><filedate>1345559303</filedate></file></files><terms><term><name>Release type</name><value>New features</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.3</name><version>7.x-3.3</version><tag>7.x-3.3</tag><version_major>3</version_major><version_patch>3</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.3</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.3.tar.gz</download_link><date>1329946249</date><mdhash>70f24086dc7acfa7fc23c6148c7f8e00</mdhash><filesize>1583249</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.3.tar.gz</url><archive_type>tar.gz</archive_type><md5>70f24086dc7acfa7fc23c6148c7f8e00</md5><size>1583249</size><filedate>1329946249</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.3.zip</url><archive_type>zip</archive_type><md5>e8b5f8d4de7526d2919993bb3a34c0bf</md5><size>1803054</size><filedate>1329946249</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.2</name><version>7.x-3.2</version><tag>7.x-3.2</tag><version_major>3</version_major><version_patch>2</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.2</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.2.tar.gz</download_link><date>1329778551</date><mdhash>c350603991445ca69b30eddf3befe887</mdhash><filesize>1582617</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.2.tar.gz</url><archive_type>tar.gz</archive_type><md5>c350603991445ca69b30eddf3befe887</md5><size>1582617</size><filedate>1329778551</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.2.zip</url><archive_type>zip</archive_type><md5>641a7c36bc39d5c17b997ff5babf6d47</md5><size>1801836</size><filedate>1329778552</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.1</name><version>7.x-3.1</version><tag>7.x-3.1</tag><version_major>3</version_major><version_patch>1</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.1</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.1.tar.gz</download_link><date>1326750948</date><mdhash>e158435dc66d1d89a0df587c39ef1a23</mdhash><filesize>1575585</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.1.tar.gz</url><archive_type>tar.gz</archive_type><md5>e158435dc66d1d89a0df587c39ef1a23</md5><size>1575585</size><filedate>1326750948</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.1.zip</url><archive_type>zip</archive_type><md5>43999fc1888c1aa88f1d20288aace84c</md5><size>1792932</size><filedate>1326750949</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.0</name><version>7.x-3.0</version><tag>7.x-3.0</tag><version_major>3</version_major><version_patch>0</version_patch><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0.tar.gz</download_link><date>1324170451</date><mdhash>1be8cbd6fd3f37bfd1493693dfa95d8d</mdhash><filesize>1461460</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0.tar.gz</url><archive_type>tar.gz</archive_type><md5>1be8cbd6fd3f37bfd1493693dfa95d8d</md5><size>1461460</size><filedate>1324170451</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0.zip</url><archive_type>zip</archive_type><md5>99769e8808519ae36171fa619cf00997</md5><size>1672723</size><filedate>1324170451</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security covered="1"/></release><release><name>views 7.x-3.0-rc3</name><version>7.x-3.0-rc3</version><tag>7.x-3.0-rc3</tag><version_major>3</version_major><version_patch>0</version_patch><version_extra>rc3</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0-rc3</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0-rc3.tar.gz</download_link><date>1321467945</date><mdhash>b3e58f4195308e37621155d3c843e53f</mdhash><filesize>1456218</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-rc3.tar.gz</url><archive_type>tar.gz</archive_type><md5>b3e58f4195308e37621155d3c843e53f</md5><size>1456218</size><filedate>1321467945</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-rc3.zip</url><archive_type>zip</archive_type><md5>502f84cfadb4bf4744b6c452fc01f2d6</md5><size>1665759</size><filedate>1321467946</filedate></file></files><terms><term><name>Release type</name><value>Security update</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security>RC releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.0-rc1</name><version>7.x-3.0-rc1</version><tag>7.x-3.0-rc1</tag><version_major>3</version_major><version_patch>0</version_patch><version_extra>rc1</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0-rc1</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0-rc1.tar.gz</download_link><date>1308341221</date><mdhash>e158db78ae2f8cc615edb910a09384b0</mdhash><filesize>1481151</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-rc1.tar.gz</url><archive_type>tar.gz</archive_type><md5>e158db78ae2f8cc615edb910a09384b0</md5><size>1481151</size><filedate>1308341221</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-rc1.zip</url><archive_type>zip</archive_type><md5>941111b41371084230bc82374ebcae19</md5><size>1682522</size><filedate>1308341221</filedate></file></files><terms><term><name>Release type</name><value>New features</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security>RC releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.0-beta3</name><version>7.x-3.0-beta3</version><tag>7.x-3.0-beta3</tag><version_major>3</version_major><version_patch>0</version_patch><version_extra>beta3</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0-beta3</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta3.tar.gz</download_link><date>1301301971</date><mdhash>114c76f201523ef3e50b9a1d431b0364</mdhash><filesize>1469580</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta3.tar.gz</url><archive_type>tar.gz</archive_type><md5>114c76f201523ef3e50b9a1d431b0364</md5><size>1469580</size><filedate>1301301971</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta3.zip</url><archive_type>zip</archive_type><md5>d69e051c8b4fa2066575c28e3ae197ba</md5><size>1671930</size><filedate>1301301971</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security>Beta releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.0-beta2</name><version>7.x-3.0-beta2</version><tag>7.x-3.0-beta2</tag><version_major>3</version_major><version_patch>0</version_patch><version_extra>beta2</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0-beta2</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta2.tar.gz</download_link><date>1301158871</date><mdhash>c39fab1e76e55b15291fecf2c10386c2</mdhash><filesize>1469243</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta2.tar.gz</url><archive_type>tar.gz</archive_type><md5>c39fab1e76e55b15291fecf2c10386c2</md5><size>1469243</size><filedate>1301158871</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta2.zip</url><archive_type>zip</archive_type><md5>cd30442906e8d9e9bffc7ea8b28f3702</md5><size>1671405</size><filedate>1301158871</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security>Beta releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.0-beta1</name><version>7.x-3.0-beta1</version><tag>7.x-3.0-beta1</tag><version_major>3</version_major><version_patch>0</version_patch><version_extra>beta1</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0-beta1</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta1.tar.gz</download_link><date>1301099796</date><mdhash>6ee4495cbdf0a8d19bd214f57bef0bf4</mdhash><filesize>1468892</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta1.tar.gz</url><archive_type>tar.gz</archive_type><md5>6ee4495cbdf0a8d19bd214f57bef0bf4</md5><size>1468892</size><filedate>1301099796</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-beta1.zip</url><archive_type>zip</archive_type><md5>36acc8675052e2dcb0c933e1ac8eab1d</md5><size>1670997</size><filedate>1301099796</filedate></file></files><terms><term><name>Release type</name><value>New features</value></term><term><name>Release type</name><value>Bug fixes</value></term></terms><security>Beta releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.0-alpha1</name><version>7.x-3.0-alpha1</version><tag>7.x-3.0-alpha1</tag><version_major>3</version_major><version_patch>0</version_patch><version_extra>alpha1</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.0-alpha1</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.0-alpha1.tar.gz</download_link><date>1294276882</date><mdhash>8635e5b0c03fed4516abae25489a5a5c</mdhash><filesize>1561161</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-alpha1.tar.gz</url><archive_type>tar.gz</archive_type><md5>8635e5b0c03fed4516abae25489a5a5c</md5><size>1561161</size><filedate>1294276882</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.0-alpha1.zip</url><archive_type>zip</archive_type><md5>f5ffc235849f2a3a5f66b66f84a73aac</md5><size>1772425</size><filedate>1294276882</filedate></file></files><terms><term><name>Release type</name><value>Bug fixes</value></term></terms><security>Alpha releases are not covered by Drupal security advisories.</security></release><release><name>views 7.x-3.x-dev</name><version>7.x-3.x-dev</version><tag>7.x-3.x</tag><version_major>3</version_major><version_extra>dev</version_extra><status>published</status><release_link>https://www.drupal.org/project/views/releases/7.x-3.x-dev</release_link><download_link>https://ftp.drupal.org/files/projects/views-7.x-3.x-dev.tar.gz</download_link><date>1491154383</date><mdhash>b8b158ae6a7c9f4e84540fbfcfa83ee3</mdhash><filesize>1643061</filesize><files><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.x-dev.tar.gz</url><archive_type>tar.gz</archive_type><md5>b8b158ae6a7c9f4e84540fbfcfa83ee3</md5><size>1643061</size><filedate>1491154383</filedate></file><file><url>https://ftp.drupal.org/files/projects/views-7.x-3.x-dev.zip</url><archive_type>zip</archive_type><md5>db78a5499cda151d5a352a908adf7e6b</md5><size>1913538</size><filedate>1491154383</filedate></file></files><security>Dev releases are not covered by Drupal security advisories.</security></release></releases>
</project>

```

In short:

---
Tags: updating
---


# Question
Title: Drupal.attachBehaviours() on Block that got rendered via ajax call
i'm rendering a form and using an alter hook for changing the form to submit via ajax. This works like a charm. ( Drupal 8 webform with webform\_ajax )

Now i want to render the form via ajax into the content. This also works.

Because the content is not there on page load i have to re-apply the drupal behaviours.

This is the thing i can't get to work.

Here's the code i use: **Form.js**

```
(function ($, Drupal) {

  'use strict';

  var $modal = $('#modal');
  var url = $('.block-system-main-block > article.node').attr('about');

  Drupal.behaviors.formInModal = {
    attach: function (context, settings) {
      $(context).find('.js-engagement-link').once('js-engagement-link').each(function () {
        var targetForm = $(this).data('target');

        $(this).click(function(){
          $.ajax({
            url: '/contact_bridge/webform/' + targetForm
          }).done(function(response) {
            $modal.find('.modal-content').first().html(response);
            $modal.foundation('open');
            Drupal.attachBehaviors($('#modal')[0], settings);
          });
        });
      });
    }
  };
})(jQuery, Drupal);

```

**Form alter:**

```
public function formAlter(array &$form, FormStateInterface $formState, $formId) {
  $webformSubmission = $formState->getFormObject()->getEntity();
  if ($this->isAvailable($webformSubmission->getWebform())) {
    $ajax = $this->getAjaxProperties($formId);
    $form['#prefix'] = '<div id="' . $ajax['wrapper'] . '">';
    $form['#suffix'] = '</div>';
    $form['actions']['submit']['#ajax'] = [
      'callback' => '\Drupal\webform_ajax\Controller\WebformAjaxController::ajaxSubmission',
      'wrapper' => $formId . '_wrapper',
    ]
  }
}

```

I tried many different calls to attachBehaviours, nothing seems to work. The alter hook is applied to the form and the ajax wrapper is there.

-- edit1 --

Here the code on the backend side for rendering the block:

```
<?php

namespace Drupal\contact_bridge\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Render\HtmlResponse;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Url;
use Drupal\webform\Entity\Webform;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 *
 */
class ContactBridgeController extends ControllerBase {

  /**
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManger;

  /**
   * @var \Drupal\Core\Render\RendererInterface
   */
  protected $renderer;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('entity_type.manager'),
      $container->get('renderer'),
    );
  }

  /**
   * {@inheritdoc}
   */
  public function __construct(
    EntityTypeManagerInterface $entityTypeManager,
    RendererInterface $renderer
  ) {
    $this->entityTypeManger = $entityTypeManager;
    $this->renderer = $renderer;
  }

  /**
   * @param string $webformid
   * @return \Drupal\Core\Render\HtmlResponse
   */
  public function getWebformBlockHtml($webformid) {
    $webform = Webform::load($webformid);
    $renderArray = $this->entityTypeManager()->getViewBuilder('webform')->view($webform);

    $html = $this->renderer->renderPlain($renderArray);
    return HtmlResponse::create($html);
  }

}

```

And the routing:

```
contact_bridge.webform:
  path: 'contact_bridge/webform/{webformid}'
  defaults:
    _controller: '\Drupal\contact_bridge\Controller\ContactBridgeController::getWebformBlockHtml'
  requirements:
    _permission: 'access content'
    webformid: ^[a-zA-Z0-9_]+

```

Can somebody tell me what i'm doing wrong?

Thanks in advance.

# Answer
Ok, there are a few things that need to be done:

1. Create a custom ajax command
2. Create the JS to handle that custom command
3. Return an AjaxResponse from getWebformBlockHtml(), that contains that custom command from step 1
4. Ajaxify the response when your ajax is complete

You can do that as follows:

# Step 1 - Create a custom ajax command

```
namespace Drupal\[MODULENAME]\Ajax;

use Drupal\Core\Ajax\CommandInterface;

class MODULENAMELoadFormCommand implements CommandInterface
{
  protected $form;

  public function __construct($form)
  {
    $this->form = $form;
  }

  /**
   * Implements Drupal\Core\Ajax\CommandInterface:render().
   */
  public function render()
  {
    return [
      'command' => 'MODULENAMELoadFormCommand',
      'form' => $this->form,
    ];
  }
}

```

# Step 2 - Create the JS to handle that custom command

Add the following to your JavaScript that you're loading on page load:

```
Drupal.AjaxCommands.prototype.MODULENAMELoadFormCommand = function(ajax, response)
{
  $modal.find('.modal-content').first().html(response.form);
  $modal.foundation('open');
  Drupal.attachBehaviors($('#modal')[0], settings);
};

```

# Step 3 - Return an AjaxResponse from getWebformBlockHtml() that contains that custom command from step 1

```
use Drupal\Core\Ajax\AjaxResponse;

public function getWebformBlockHtml($webformid) {
  $response = new Ajaxresponse();

  $webform = Webform::load($webformid);
  $renderable = $this->entityTypeManager()->getViewBuilder('webform')->view($webform);

  $rendered_form = \Drupal::service('renderer')->renderRoot($renderable);
  $response->setAttachments($renderable['#attached']);

  $response->addCommand(new MODULENAMELoadFormCommand($rendered_form));

  return $response;
}

```

# Step 4 - Ajaxify the response when your ajax is complete

Modify your original Ajax Call to look like this:

```
$.ajax({
  url: '/contact_bridge/webform/' + targetForm,
  success:function(response) {
    var ajaxObject = Drupal.ajax({
      url: "",
      base: false,
      element: false,
      progress: false
    });

    // Simulate an AJAX response having arrived, and let the Ajax
    // system handle it.
    ajaxObject.success(response, "success");
  }
});

```
> 3 votes

---
Tags: 8, ajax, webforms
---


# Question
Title: How can I change the temporary file directory path without the UI?
In Drupal 8, Is there any way to change the temporary file directory path if I don't have access to the UI page `/admin/config/media/file-system`, either with Drush or by modifying a config file?

# Answer
## Drush

`drush config:set system.file path.temporary /tmp -y`

## settings.php

If done through `settings.php` it will no longer be changeable via either the interface or Drush.

### Drupal 8.8+

See the change record.

```
$settings['file_temp_path'] = '/tmp';

```

### Drupal 8.7 and below

```
$config['system.file']['path']['temporary'] = '/tmp';

```
> 20 votes

---
Tags: 8
---


title: How to install Commerce 2 on Drupal VM?

text:
# Question
Title: How to install Commerce 2 on Drupal VM?
I have a virtual machine running with a standard install of Drupal 8 on windows. See Drupal VM

I want to install Drupal Commerce 2 on the VM.

Do i use composer like the Commerce instructions say (composer create-project drupalcommerce/project-base mystore --stability dev).

If so where? In de folder on windows that I installed the VM in, or in the part after i use vagrant ssh (vagrant@drupalvm:~$).

Or do i need to customize one of the .yml files and then do a vagrant provision?

Please help. (sorry if I am to noob)

# Answer
Like the Commerce docs say, you need to install it like any other Drupal 8 site. So, it is easier to use the composer command.

`composer create-project drupalcommerce/project-base MYNEWSITE --stability dev`

Where MYNEWSITE is the new Drupal 8 w Commerce 2 directory. You can do this anywhere on the host machine (ex. I always have them in /Sites).

From here, you can add Drupal VM to the project and tailor the config.yml to your needs, then `vagrant up` \- just like you did with the vanilla Drupal 8 site you already installed. You should see the Commerce install screen.

There is likely a way to automate this with DrupalVM, though I have not tried that approach.
> 1 votes

---
Tags: 8, commerce, composer
---