# Question
Title: Drush error on core update "corrupt (wrong md5 checksum)"
I'm getting this error when I try to update core with Drush:

```
File drupal-7.41.tar.gz is corrupt (wrong md5 checksum).  [error]
Updating project drupal failed. Attempting to roll back to previously
installed version.   [error]

```

I've tried to refresh and clear all the caches I can think of (`drush rf`, `drush cc all`, `drush cc drush`) but the error continues.

Any ideas?

# Answer
By looking at this drupal issue queue thread, https://www.drupal.org/node/1961304 , if you are using Drush Make and having problems try `--no-cache` option for your build.

Otherwise assure the downloaded Drupal version, or module, is readable by the Drush user. If drush cannot read the file then the md5 checksum cannot be run and Drush will report a corrupt file:

> @sobi3ch: this appears to be a permissions issue. If i'm reading the Drush output correctly, "md5\_file(/var/www/vhosts/etcc.pl/drupal-7.38.tar.gz): failed to open stream: Permission denied" is saying the md5 checksum function is unable to open the file to validate the checksum on it, which causes drush to think the file has the wrong checksum.
> 1 votes

# Answer
If anyone else finds this answer unsatisfactory, try passing the undocumented `--no-md5` flag to `drush up`
> 1 votes

# Answer
Okay, the error seems to be a bit of a red herring as it seems to have been a directory permissions issue. I moved the site to a new directory recently and one of the parent folders was not writable. Changing that has fixed this issue for me.
> 0 votes

---
Tags: drush, updating, security
---


# Question
Title: How to remove paragraph tag from ckeditor?
When we insert content into ckeditor field,suppose we write single line of text into ckeditor without any html tag, why its wrapping **paragraph** tag automatically around the text .

I need to remove this **paragraph tag** because its breaking my page's structure.

# Answer
> 3 votes
In Drupal 8, you may need to implement `hook_editor_js_settings_alter` and set `config.autoParagraph` to false, as referenced here: CKEDITOR.config.autoParagraph

```
/**
 * Implements hook_editor_js_settings_alter().
 */
function MODULE_editor_js_settings_alter(array &$settings) {
  foreach ($settings['editor']['formats'] as $name => $value) {
    $settings['editor']['formats'][$name]['editorSettings']['autoParagraph'] = FALSE;
  }
}

```

# Answer
> 0 votes
In Drupal 7 you have to go to admin/config/content/ckeditor press "edit" in the profile you want to change, and then under "Custom JavaScript configuration" (in advanced options section) add this line:

```
config.enterMode = CKEDITOR.ENTER_DIV;

```

more info in the original answer by alex-petrov:

https://drupal.stackexchange.com/a/30995/55010

# Answer
> 0 votes
In Drupal 8 using CKeditor if you change the text format to 'Full HTML' (to allow div tags) then click on source and then change the `<p>` for a `<div>` then it will not automatically add the `<p>` tags in next time it loads the content.

This is because, (as clive mentioned) there needs to be a block level element at the root of the document.

This is often less problematic than wrapping it in a `p` tag as sites are less likely to have global `div` styles, spacing, borders, padding, etc.

# Answer
> 0 votes
If you don't have a `<p>` in the Allowed HTML tags and enable the "Limit allowed HTML tags and correct faulty HTML" filter no `<p>` will be output on the front end. These settings appear per text format seen at `/admin/config/content/formats`.

The Allowed Formats module allows you to restrict certain fields to specific formats. This way you can restrict this field to a specific text format, a format that does not allow `<p>` tags, but allow them everywhere else.

---
Tags: 8, wysiwyg
---


title: Programmatically Render a Webform

text:
# Question
Title: Programmatically Render a Webform
I'm attempting to render a webform inside a block plugin. I'm able to successfully retrieve the webform using the following code

```
$webform = \Drupal::entityTypeManager()->getStorage('webform')->load('my_webform');

```

However I'd like to render this form. I've attempted using

```
return $webform;

```

But I receive the error

> Recoverable fatal error: Argument 1 passed to Drupal\Core\Render\Element::isEmpty() must be of the type array, object given

I'm assuming this is because $webform isn't formatted as a proper render array, but I'm not sure how to do this. I've been searching for clues inside the code of the original webform module, but I haven't been able to find anything.

How would I programmatically render a webform? And/or is there a way to find in the code of a module or entity the way to render that entity?

# Answer
> 15 votes
I managed to find a method for the webform entity class called getSubmissionForm. I found it in the webform module code in src/Entity/Webform.php

I invoked it like so

```
$webform = \Drupal::entityTypeManager()->getStorage('webform')->load('my_webform');
$webform = $webform->getSubmissionForm();

return $webform;

```

Which returned the specified webform rendered.

# Answer
> 12 votes
You can also just return a render array.

```
[
  '#type' => 'webform',
  '#webform' => 'my_webform',
  '#default_data' => [
    'nid' => 10
  ]
]

```

# Answer
> 8 votes
Matt answers works for me but if you want to have a more complete theme structure with it, you would better use :

```
$webform      = \Drupal::entityTypeManager()->getStorage('webform')->load('my_webform');
$view_builder = \Drupal::service('entity_type.manager')->getViewBuilder('webform');
$build        = $view_builder->view($webform);
return $build;

```

> To render this webform as a render array and to add it to your output

# Answer
> 2 votes
To render a Webform inside a Block plugin, you can use Block Token module for that. It will allow you to create the tokens for your blocks.

To create a webform block, go to *Block Layout*, then *Place* a block, then check the *Create the token for this block* checkbox for the block. Now the specific webform should be available as a block.

Here is the example to manually render the above created webform block:

```
$block = BlockViewBuilder::lazyBuilder('mywebform', 'full', 1);
$block_content = render($block);

```

---
Tags: 8, webforms
---


# Question
Title: True/False exposed Views checkbox for Computed Field
Imagine a user has ten fields of type "List(text)" which each have for their widget "Check boxes/radio buttons". Each one is displayed to the user as a single value checkbox which asks the user to state whether they agree with something or not.

A distinct Computed Field of data type TinyInt uses custom PHP to examine the values of these List(text) fields checkboxes. If all are checked the Computed Field is set to have the value of 1. If any or all are unchecked the Computed Field is set to have the value of 0.

(Ideally I would like the Computed Field to be of Boolean type - so simple TRUE/FALSE - but this does not seem possible out of the box. Anyway, the real question is the following.)

In a View with exposed fields, how can you use the Computed Field as an exposed field that offers the user a single checkbox: "Find all users where the Computed Field value is 1: \[•\]".

If this isn't directly possible, I'm happy to have a workaround that involves creating a distinct (hidden) field in the user profile and then uses this for the Views exposed filter search. But I can't think of a way to do this right now... Thanks.

# Answer
1. Change exposed computed field's filter type to "Grouped filters",
2. Widget type to "Radios",
3. Check "Allow multiple selections" checkbox,
4. Expose one option equal to 1 with your choice of label

See screenshot:

The view export:

```
<?php

$view = new view();
$view->name = 'computed_field_test';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Computed Field Test';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Computed Field Test';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['exposed_form']['options']['autosubmit'] = TRUE;
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Field: Content: List 1 */
$handler->display->display_options['fields']['field_list_1']['id'] = 'field_list_1';
$handler->display->display_options['fields']['field_list_1']['table'] = 'field_data_field_list_1';
$handler->display->display_options['fields']['field_list_1']['field'] = 'field_list_1';
/* Field: Content: List 2 */
$handler->display->display_options['fields']['field_list_2']['id'] = 'field_list_2';
$handler->display->display_options['fields']['field_list_2']['table'] = 'field_data_field_list_2';
$handler->display->display_options['fields']['field_list_2']['field'] = 'field_list_2';
/* Field: Content: Computed */
$handler->display->display_options['fields']['field_computed']['id'] = 'field_computed';
$handler->display->display_options['fields']['field_computed']['table'] = 'field_data_field_computed';
$handler->display->display_options['fields']['field_computed']['field'] = 'field_computed';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'page' => 'page',
);
/* Filter criterion: Content: Computed (field_computed) */
$handler->display->display_options['filters']['field_computed_value']['id'] = 'field_computed_value';
$handler->display->display_options['filters']['field_computed_value']['table'] = 'field_data_field_computed';
$handler->display->display_options['filters']['field_computed_value']['field'] = 'field_computed_value';
$handler->display->display_options['filters']['field_computed_value']['exposed'] = TRUE;
$handler->display->display_options['filters']['field_computed_value']['expose']['operator_id'] = 'field_computed_value_op';
$handler->display->display_options['filters']['field_computed_value']['expose']['label'] = 'Computed (field_computed)';
$handler->display->display_options['filters']['field_computed_value']['expose']['operator'] = 'field_computed_value_op';
$handler->display->display_options['filters']['field_computed_value']['expose']['identifier'] = 'field_computed_value';
$handler->display->display_options['filters']['field_computed_value']['expose']['multiple'] = TRUE;
$handler->display->display_options['filters']['field_computed_value']['is_grouped'] = TRUE;
$handler->display->display_options['filters']['field_computed_value']['group_info']['identifier'] = 'field_computed_value';
$handler->display->display_options['filters']['field_computed_value']['group_info']['optional'] = FALSE;
$handler->display->display_options['filters']['field_computed_value']['group_info']['widget'] = 'radios';
$handler->display->display_options['filters']['field_computed_value']['group_info']['multiple'] = TRUE;
$handler->display->display_options['filters']['field_computed_value']['group_info']['group_items'] = array(
  1 => array(
    'title' => 'Find all users where the Computed Field value is 1',
    'operator' => '=',
    'value' => array(
      'value' => '1',
      'min' => '',
      'max' => '',
    ),
  ),
  2 => array(
    'title' => '',
    'operator' => '=',
    'value' => array(
      'value' => '',
      'min' => '',
      'max' => '',
    ),
  ),
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'computed-field-test';
$handler->display->display_options['menu']['type'] = 'normal';
$handler->display->display_options['menu']['title'] = 'Computed Field Test';
$handler->display->display_options['menu']['name'] = 'devel';

```
> 0 votes

---
Tags: 7, views
---


# Question
Title: How to create a field that references a Views Block display in D8?
In D7, using the blockreference contrib module, you could add a field to a node (say) that allowed the user to reference a **block**. When viewing the page the referenced block's rendered content would be included.

This was great for including widgety stuff on a per-page basis, especially when combined with the Paragraphs module.

I have a View which defines a number of Block displays. I want to reference a particular one from a node and I'm struggling to do this in D8.

When creating the reference field, I'm offered various things under the "References" optgroup, but none include Block. I tried "References » Other..." which seemed to be the generic entity reference that I thought would work.

Next I'm asked what type of entity to reference, which is split between **content** and **config**. I suppose this is config since a view is config, even if its config that provides content (ouch my brain). Under Config I see **block**. Great! I want it to reference a block.

However, after selecting that I cannot seem to reference the block created by my view - switching the form display to select list to see what *is* available I see all sorts of stuff (some, like "primary admin actions" apparently repeated 4 times?!) but NOT the view's blocks.

The other option that looked relevant for "which entity to reference" is View. But if I do that I just get a link to the view's edit screen.

I've since found that if I *place* the block in the *disabled* section, then I am able to reference it.

So is there a better way to reference a block or do I have to do this odd thing of *create a block » place as "disabled" » reference*. Alternatively, is there an explanation why having to do things this really confusing way brings an important benefit to site building that I ought to understand?

Thanks in advance.

# Answer
> 4 votes
Block field actually cover the same functionnality that Drupal blockreference did. It works like "block field" in display suite, it reference block plugin and create block instances related to it host entity, not any theme.

# Answer
> 4 votes
Things are confusing because that's how entity reference works. All those things are entities, so they are technically referencable. As you found, block are actual block *placements*, which is not what you want. And view doesn't allow to select the display, so for your case, that's also not what you want. Drupal 8 core simply can't do that without custom code or a module (yet).

You either need a contrib module like Viewfield, but that doesn't have an official 8.x release yet. The blue box points to the contrib tracker issue, which in turn points to https://www.drupal.org/node/2220929, which has a link to a github repository where someone did an initial port. If and how well that is working already, I can't say.

An approach that would require a bit of custom code would be to have a list field with a few options ( since you don't want to allow all views anyway..), and based on that, there needs to be a bit of code that loads and calls the view and displays the results.

# Answer
> 4 votes
At my work we are testing Drupal 8 (currently 8.2.5) and had the same issue, but we are using the Paragraphs Module for page content layouts. We have found a solution that has been working so far.

First, you would need to install the Paragraphs module. Then you would install the Views Reference Field module. Once you create a "paragraph" you can add a field for a "view reference" and it will load the data for that view into the specified section of the "paragraph". Once we added the Paragraph field to the content type we wished to use it on, we are now able to load the data for any of our views into any part of the pages fields.

NOTE: we have not tested the Views Reference Field module on it's own, but it may be worth a try!

The documentation for each of these modules is pretty good and got us where we needed to be so I won't bother going over all the details of each here, you should read and play with them accordingly.

# Answer
> 1 votes
You can actually do this with the Block Visibility Groups Module. When you install the module, an item will appear in the admin bar, "Block Visibility Groups." When you are on the page where you wish to place the block, just click on it, and it will give you a number of options on how to limit the visibility of the block you want to place on the page. I am using it to display a views block with a contextual NID filter on a node type I have called Photo Galleries, and it pulls in the images from the image field and formats them into a Views Slideshow. I limited the visibility to the Photo Gallery content type.

Then, after creating the Visibility Group, go to the block layout page, and a drop down will appear just above the regions, and you can select your Visibility Group from there. When you place your block with that Visibility group selected, it will limit the display of the block in the region to the visibility group you designated.

Works very well, just requires a slightly different way of thinking about it over the field formatters.

# Answer
> 1 votes
This is one of my favorite questions. Although this relies on Display Suite and I haven't tried the solution, I want to share it:

1. Install Display Suite
2. Use DS on any of your content items (/admin/structure/ds)
3. "Add a block field" (/admin/structure/ds/fields/manage\_block)
4. Select the Views Block from the Dropdown list

You find the more detailed explanation by Ivan Zugec here: https://www.webwash.net/using-display-suite-drupal-8-how-to-use-display-suite-fields/

# Answer
> 1 votes
I added the view block using the Entity reference field type (choose other).

There is a great tutorial here: https://www.mediacurrent.com/blog/drupal-8-how-reference-views-block-display-field/

This is will work great on nodes but it's super powerful in conjunction with Paragraphs.

---
Tags: entities, 8
---


title: Paragraph view reference?

text:
# Question
Title: Paragraph view reference?
I am trying to meet the following requirement:

I want to create a node (custom content type) that contains only a paragraph reference.

I have the following paragraphs in my node

* Billboard (large image + Caption)
* Testmonial (slideshow sentences)
* Body
* **Here i want to display a view that contains news articles (nodes from the custom news content type)**
* Call to action

But i can't seem to do this properly?

I can create a block display for my view and attach it to the page by path, but then the view is located **below** my paragraphs, where I want the view to be **one of the paragraphs**, since there is a call to action that needs to be located below the view.

Anyone ever tried this?

All suggestions welcome!

*If you have a solution that does not use paragraphs, I am also happy to hear!*

Many thanks in advance

**EDIT:** After some additional searching, it seems that for D7, this module seems to be capable of doing this: https://www.drupal.org/project/entityreference\_views\_formatter more information can be found here: https://www.drupal.org/node/2756315

Still no solution for D8 though...

# Answer
Using hook\_entity\_view, you can insert the view into the field's build array.

```
function mymodule_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {

  if ($entity->getEntityType()->id() == 'node' && $entity->bundle() == 'example_content_type' && $view_mode == 'full') {
    $node_id = \Drupal::routeMatch()->getRawParameter('node');
    $index = 0;
    foreach($build['field_paragraph_field'] as $key => $value) {

      if (is_numeric($key) && $value['#paragraph']->bundle() == 'body') {
        $news_view = [
          '#type' => 'view',
          '#name' => 'my_news_feed',
          '#display_id' => 'block_1',
          '#arguments' => [$node_id],
        ];

        array_splice($build['field_paragraph_field'], $index + 1, 0, [$news_view]);

      }
      $index++;
    }
  }

}

```
> 3 votes

# Answer
Check out the Views Reference Field module. This module provides a new field type that allows you to reference a view display similar to an entity reference field. After installing the module create a new paragraph type with a viewsreference field. You now have a paragraph type that displays a view.
> 1 votes

# Answer
You should be able to acheive this with any module that can add a view as a field. Currently for D8:

* Display Suite
* Entity views attachment
* Viewfield
* Display fields
> 0 votes

# Answer
I did this by adding a paragraph type that is one Entity reference field.

There is a tutorial here: https://www.mediacurrent.com/blog/drupal-8-how-reference-views-block-display-field/

It works great and takes paragraphs to the next level.
> 0 votes

---
Tags: nodes, 8
---


title: Custom display suite template

text:
# Question
Title: Custom display suite template
I'm trying to understand Drupal 8 theming, since I want some custom layouts for some of my pages. I've tried Display Suite module, and it gets me some of the way, but non of the display suite layouts offers the exact layout I need.

How do I make my own Display Suite layouts? I have made a copy of the layout template files from ds/templates to mythemename/templates/generated, and renamed the file as Display Suite tells me to. When I open that file, I see Header, Left, Right and Footer "regions". But how would I go about adding new regions to that template? I understand how to add block-regions to a website, but that seems to be something different than the "regions" in a display suite template.

And if I edit a display suite template, would I somehow be able to rename it to, lets say, "mytemplate", and make it appear in the drop-down box from where you select what display-suite template to use?

# Answer
You can create your own layouts in a module or theme by defining a `my_module.layouts.yml` or `my_theme.layouts.yml` file. Then you'll have to create the templates for your layouts where you output the regions.

This is the layout definition for the DS 2 Col Fluid layout (ds.layouts.yml):

```
ds_2col_fluid:
  label: Fluid two column layout
  category: Display Suite
  class: '\Drupal\ds\Plugin\DsLayout'
  type: partial
  template: templates/ds-2col-fluid
  library: ds/ds_2col_fluid
  icon: images/ds-2col-fluid.png
  regions:
    left:
      label: Left
    right:
      label: Right

```

`label` defines the label that's displayed when you're selecting your layout on the Manage Display screens.

`category` defines the option group that your layout appears in on the Manage Display screen. It can be helpful to use My Module or My Theme here to group all layouts defined by your module or theme.

`class` I've never had to change this to anything else to anything other than `\Drupal\ds\Plugin\DsLayout`

`type` I've never set this to anything other than `partial`. I'm not sure what the other options are.

`template` defines the template file to use. This should be the relative path, from your module or theme, to the template.

`library` allows you to load a drupal library as a dependency when you're layout is being rendered. Add js or css that you may need.

`icon` defines the path to the icon that appears on Manage Display screens to represent your layout.

`regions` define the regions of your layout.

As far as I know you don't need to include the icon or library parameters and it won't cause any errors.

Your template file will have variables for content, attributes, html element for each region, layout and outer wrapper. See `ds/templates/ds-2col-fluid`

Here's an example for how you can render a region you defined in your `layouts.yml` file (taken from `ds/templates/ds-2col-fluid`):

```
{% set left = left|render %}
{% if left %}
  <{{ left_wrapper }}{{ left_attributes.addClass('group-left') }}>
    {{ left }}
  </{{ left_wrapper }}>
{% endif %}

```

If you define your layouts and templates in a module file, you can later override the templates in a theme if needed, as you can with any standard template in drupal.
> 2 votes

---
Tags: display-suite
---


# Question
Title: Is it possible to add fields definitions in entity?
I created an entity using `drupal` console and now I would like to add fields to it. These should be references to other entities. I want these fields to be added programmatically, in the code. Ideally in the entity class so I can use entity methods to load referenced entities. How do I do that?

Thanks.

# Answer
> 3 votes
When you create an entity using Drupal Console you'll find such a field as example already defined in baseFieldDefinitions(), which references the user entity:

```
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
  ->setLabel(t('Authored by'))
  ->setDescription(t('The user ID of author of the {{ label }} entity.'))
  ->setRevisionable(TRUE)
  ->setSetting('target_type', 'user')
  ->setSetting('handler', 'default')
  ->setTranslatable(TRUE)
  ->setDisplayOptions('view', [
    'label' => 'hidden',
    'type' => 'author',
    'weight' => 0,
  ])
  ->setDisplayOptions('form', [
    'type' => 'entity_reference_autocomplete',
    'weight' => 5,
    'settings' => [
      'match_operator' => 'CONTAINS',
      'size' => '60',
      'autocomplete_type' => 'tags',
      'placeholder' => '',
    ],
  ])
  ->setDisplayConfigurable('form', TRUE)
  ->setDisplayConfigurable('view', TRUE);

```

You can define as target other entities:

```
  ->setSetting('target_type', 'my_other_entity')

```

BTW the two last two lines of the example make this base field configurable in UI. You can set this to FALSE if you don't want that anyone can change the configuration you've made in code.

You can customize this, for example if you want a dropdown select element:

```
  ->setDisplayOptions('form', [
    'type' => 'options_select',
    'weight' => 5,
    'settings' => [
    ],

```

To implement code to load the referenced entities extend the field widget `OptionsSelectWidget`, add a custom plugin id to the annotations `my_options_select`, which you can use for the type in the example above

```
    'type' => 'my_options_select',

```

and override the plugin methods to load the options. For simple cases use hook\_options\_list\_alter, this hook is invoked by the widget base class method `getOptions()`.

---
Tags: 8, entities
---


title: View title change based on context

text:
# Question
Title: View title change based on context
I have a view that lists nodes of a certain type "TypeA" using their titles (and a link to click on).
The view filters out the current TypeA node from that list using a contextual filter set to Content:ID with a default value passed in through the request URL, and the "Exclude" checkbox ticked.
Consequently, when the currently displayed node is *not* of TypeA, *all* nodes of TypeA are listed.

I want the block in which the view is displayed to change title depending on whether I view a node of TypeA or not, as follows:

1. Node is of TypeA, the title is set to "Other TypeAs"
2. Otherwise, the title is set to "All TypeAs"

I don't know how to further test the query result for the condition, or change the contextual filter (since I *always* have a Content:ID passed in) to make that happen.

One possible workaround could be to trigger on the URL path because all nodes of TypeA have a custom URL path (via the Pathauto module) configured.

I am using Drupal 8.4.6, soon to migrate to 8.5.

# Answer
You can implement a hook in your module. Ex:

```
/**
 * Update title of block based on the node type currently being viewed.
 *
 * Implements hook_block_view_alter().
 */
function my_module_block_view_alter(&$build, \Drupal\Core\Block\BlockPluginInterface $block) {
  // Only act on the block you want.
  if ($build['#id'] == 'your_block_id') {
    // Attempt to get the current node object from the route.
    $node = \Drupal::routeMatch()->getParameter('node');
    if ($node instanceof \Drupal\node\NodeInterface) {
      if ($node->getType() == 'type_a') {
        $build['#configuration']['label'] = t('Other Type As');
      }
      else {
        $build['#configuration']['label'] = t('All Type As');
      }
    }
  }
}

```

See api documentation for hook\_block\_view\_alter for more info.
> 0 votes

---
Tags: views, 8
---


title: alterRoutes() is not triggered

text:
# Question
Title: alterRoutes() is not triggered
I am trying to alter the route for the login and registration pages. I followed Altering existing routes and adding new routes based on dynamic ones. I cleared the cache repeatedly, and re-enabled the module several times, but it looks like `alterRoutes()` is not triggered, even when I try to add a `kint()` debug or any code.

What I noticed is that `alterRoutes()` -\> `kint()` is triggered when I use Drush to enable the module. In this case, I see `kint()` output in my terminal. However, `alterRoutes()` is not triggered when viewing the site.

This is the code I am using.

### md\_routes/src/Routing/RouteSubscriber.php

```
namespace Drupal\md_routes\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Drupal\Core\Routing\RoutingEvents;
use Symfony\Component\Routing\RouteCollection;
/**
 * Listens to the dynamic route events.
 */
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    kint($collection);
    // Change path '/user/login' to '/login'.
    if ($route = $collection->get('user.login')) {
      $route->setPath('/login');
    }
    if ($route = $collection->get('user.register')) {
      $route->setPath('/register');
    }
  }
}

```

### md\_routes/md\_routes.services.yml

```
services:
  md_routes.route_subscriber:
    class: Drupal\md_routes\Routing\RouteSubscriber
    tags:
      - { name: event_subscriber }

```

# Answer
I did clear the drupal caches using the interface (admin/config/development/performance), it seems like drush is not clearing ALL caches. It does work now and i guess it was a caching issue. Thanks anyways!
> -1 votes

---
Tags: 8
---


# Question
Title: How do I retrieve the user ID of the latest editor of a node?
I know how to get the user who created a node after getting the node object.

```
$node = \Drupal::routeMatch()->getParameter('node');
$uid = $node->getOwnerId();
$user = \Drupal\user\Entity\User::load($uid);

```

Since an alternative to retrieving values of the node object is for example `$node->nid->value`, I tried to get the revision user ID this way.

```
$ruid = $node->revision_uid->value;

```

Unfortunately, this doesn't work, although I see with the Devel module that there is a value. So what is the equivalent in Drupal 8 to `$node->revision_uid` in Drupal 7?

# Answer
`$node->getOwnerID()` returns the user ID for the user who created the node. If you need the user who created the revision, you need to use `$node->getRevisionUser()`, or `$node->getRevisionUserId()` for the user ID.
> 4 votes

---
Tags: 8
---


# Question
Title: Is it safe to delete all revisions of a deleted node?
I'm trying to import nodes from a Drupal 7 database to a brand new Drupal 8 one using the Feeds module.

I'v imported stuff and then deleted it (because I'm testing at the moment the best way to do it). I keep deleting nodes, but I've noticed that the revision tables are full of stuff.

Currently there is no node in the site, but the revision tables are occupying 50MB already.

Is it safe to empty all those tables?

# Answer
> 1 votes
I hope you are doing your tests on a test server. In that case, yes, they are safe to be emptied, even if it would be better to let Drupal and any third-party module to remove any entity data they have in their tables.

Rather than worrying to empty tables, I would find a quicker way to create a test server that is then destroyed when the test is done.

---
Tags: nodes
---


# Question
Title: Can't connect to DB while installing Drupal 8
Can't connect to DB while installing Drupal 8. DB is located on localhost acording to direct admin but i can get to DB only when using ip address in advanced options of drupal installation otherwise i get: SQLSTATE\[HY000\] \[2002\] No such file or directory. With ip entered it says following message: SQLSTATE\[HY000\] \[1045\] Access denied for user on server.......

I have tried different users and db that i have created on server (granted all permissions). No luck.

I have no problem logging to that DB with that user using phpmyadmin. What does it seem to be the problem ?

# Answer
> 2 votes
Instead of localhost, try 127.0.0.1

---
Tags: 8, database, installation
---


# Question
Title: Drush migrate commands do not appear after fresh drupal 8 install using composer
I am trying to follow the upgrade using drush tutorial but I cannot get the migrate commands to appear in drush. On a new Ubuntu 16 box I do:

```
#install a new drupal 8
composer create-project drupal-composer/drupal-project:8.x-dev drupal8 --stability dev --no-interaction
cd drupal8
composer install

#install drush
composer require drush/drush
cd /var/www/drupal8
wget -O drush.phar https://github.com/drush-ops/drush-launcher/releases/download/0.6.0/drush.phar
sudo mv drush.phar /usr/local/bin/drush
chmod +x /usr/local/bin/drush

```

I then go to the website and set it up. It creates the database etc. Everything seems OK. Then, I install the migration packages

```
cd /var/www/drupal8/drupal8
composer require drupal/migrate_upgrade
composer require drupal/migrate_plus
composer require drupal/migrate_tools
# Enable migration packages
drush en migrate migrate_drupal migrate_upgrade migrate_plus migrate_tools
drush cr
drush cc drush

```

At this point I have the migration packages installed and enabled:

```
% drush pml | grep Migration
  Migration             Migrate (migrate)                                  Enabled    8.5.1
  Migration             Migrate Advanced Example Setup                     Disabled   8.x-2.0-beta2
  Migration             Migrate Example Setup (migrate_example_setup)      Disabled   8.x-2.0-beta2
  Migration             Migrate Plus (migrate_plus)                        Enabled    8.x-2.0-beta2
  Migration             Migrate Tools (migrate_tools)                      Enabled    8.x-2.0-beta1
  Migration             Drupal Upgrade (migrate_upgrade)                   Enabled    8.x-2.0-beta1

```

and yet, `drush list` does not show any migrate commands:

```
%drush list
Drush Commandline Tool 9.2.1

Run `drush help [command]` to view command-specific help.  Run `drush topic` to read even more documentation.

 Available commands:
 _global:
   help                                       Display usage details for a command.
   list                                       List available commands.
   updatedb (updb)                            Apply any database updates required (as with running
                                              update.php).
   runserver (rs, serve)                      Runs PHP's built-in http server for development.
   browse                                     Display a link to a given path or open link in a
                                              browser.
   version                                    Show Drush version.
   generate (gen)                             Generate boilerplate code for
                                              modules/plugins/services etc.
   drupal:directory (dd)                      Return the filesystem path for modules/themes and
                                              other key folders.
   updatedb:status (updbst)                   List any pending database updates.
   twig:compile (twigc)                       Compile all Twig template(s).
 cache:
   cache:get (cg)                             Fetch a cached object and display it.
   cache:clear (cc)                           Clear a specific cache, or all Drupal caches.
   cache:set (cs)                             Cache an object expressed in JSON or var_export()
                                              format.
   cache:rebuild (cr, rebuild)                Rebuild a Drupal 8 site.
 config:
   config:pull (cpull)                        Export and transfer config from one environment to
                                              another.
   config:get (cget)                          Display a config value, or a whole configuration
                                              object.
   config:set (cset)                          Set config value directly. Does not perform a config
                                              import.
   config:edit (cedit)                        Open a config file in a text editor. Edits are
                                              imported after closing editor.
   config:delete (cdel)                       Delete a configuration key, or a whole object.
   config:status (cst)                        Display status of configuration (differences between
                                              the filesystem configuration and database
                                              configuration).
   config:export (cex)                        Export Drupal configuration to a directory.
   config:import (cim)                        Import config from a config directory.
 core:
   core:topic (topic)                         Read detailed documentation on a given topic.
   core:init (init)                           Enrich the bash startup file with bash aliases and a
                                              smart command prompt.
   core:edit (conf, config)                   Edit drushrc, site alias, and Drupal settings.php
                                              files.
   core:rsync (rsync)                         Rsync Drupal code or files to/from another server
                                              using ssh.
   core:status (status, st)                   An overview of the environment - Drush and Drupal.
   core:execute (exec, execute)               Execute a shell command. Usually used with a site
                                              alias.
   core:cron (cron)                           Run all cron hooks in all active modules for
                                              specified site.
   core:requirements (status-report, rq)      Information about things that may be wrong in your
                                              Drupal installation.
 entity:
   entity:updates (entup)                     Apply pending entity schema updates.
   entity:delete (edel)                       Delete content entities.
 image:
   image:flush (if)                           Flush all derived images for a given style.
   image:derive (id)                          Create an image derivative.
 locale:
   locale:check                               Checks for available translation updates.
   locale:update                              Imports the available translation updates.
 php:
   php:eval (eval, ev)                        Evaluate arbitrary php code after bootstrapping
                                              Drupal (if available).
   php:script (scr)                           Run php a script after a full Drupal bootstrap.
   php:cli (php, core:cli, core-cli)          Open an interactive shell on a Drupal site.
 pm:
   pm:security (sec)                          Check Drupal Composer packages for pending security
                                              updates.
   pm:enable (en)                             Enable one or more modules.
   pm:uninstall (pmu)                         Uninstall one or more modules and their dependent
                                              modules.
   pm:list (pml)                              Show a list of available extensions (modules and
                                              themes).
 queue:
   queue:run                                  Run a specific queue by name.
   queue:list                                 Returns a list of all defined queues.
   queue:delete                               Delete all items in a specific queue.
 role:
   role:create (rcrt)                         Create a new role.
   role:delete (rdel)                         Delete a new role.
   role:perm:add (rap, role-add-perm)         Grant specified permission(s) to a role.
   role:perm:remove (rmp, role-remove-perm)   Remove specified permission(s) from a role.
   role:list (rls)                            Display a list of all roles defined on the system.
 site:
   site:ssh (ssh)                             Connect to a Drupal site's server via SSH.
   site:install (si, sin)                     Install Drupal along with
                                              modules/themes/configuration/profile.
   site:set (use)                             Set a site alias that will persist for the current
                                              session.
   site:alias (sa)                            Show site alias details, or a list of available site
                                              aliases.
   site:alias-convert (sa-convert, sac)       Convert legacy site alias files to the new yml
                                              format.
 sql:
   sql:connect                                A string for connecting to the DB.
   sql:create                                 Create a database.
   sql:drop                                   Drop all tables in a given database.
   sql:cli (sqlc)                             Open a SQL command-line interface using Drupal's
                                              credentials.
   sql:query (sqlq)                           Execute a query against a database.
   sql:dump                                   Exports the Drupal DB as SQL using mysqldump or
                                              equivalent.
   sql:sync                                   Copy DB data from a source site to a target site.
                                              Transfers data via rsync.
   sql:sanitize (sqlsan)                      Sanitize the database by removing or obfuscating
                                              user data.
 state:
   state:get (sget)                           Display a state value.
   state:set (sset)                           Set a state value.
   state:delete (sdel)                        Delete a state entry.
 theme:
   theme:enable (then)                        Enable one or more themes.
   theme:uninstall (thun)                     Uninstall theme.
 user:
   user:login (uli)                           Display a one time login link for user ID 1, or
                                              another user.
   user:information (uinf)                    Print information about the specified user(s).
   user:block (ublk)                          Block the specified user(s).
   user:unblock (uublk)                       UnBlock the specified user(s).
   user:role:add (urol, user-add-role)        Add a role to the specified user accounts.
   user:role:remove (urrol, user-remove-role) Remove a role from the specified user accounts.
   user:create (ucrt)                         Create a user account.
   user:cancel (ucan)                         Cancel user account(s) with the specified name(s).
   user:password (upwd)                       Set the password for the user account with the
                                              specified name.
 views:
   views:dev (vd)                             Set several Views settings to more
                                              developer-oriented values.
   views:list (vl)                            Get a list of all views in the system.
   views:execute (vex)                        Execute a view and show a count of the results, or
                                              the rendered HTML.
   views:analyze (va)                         Get a list of all Views and analyze warnings.
   views:enable (ven)                         Enable the specified views.
   views:disable (vdis)                       Disable the specified views.
 watchdog:
   watchdog:show (wd-show, ws)                Show watchdog messages.
   watchdog:list (wd-list)                    Interactively filter the watchdog message listing.
   watchdog:delete (wd-del, wd-delete, wd)    Delete watchdog log records.
   watchdog:show-one (wd-one)                 Show one log record by ID.

```

Drush version is:

```
% drush --version
Drush Launcher Version: 0.6.0
Drush Commandline Tool 9.2.1

```

I can see the packages are installed in the `web/modules/contrib` directory, where I find `migrate_tools/migrate_tools.drush.inc`. Drush should be finding this file and adding the commands in it. Why isn't it?

------------------- Update:

My website's `admin/modules/update` page told me that my migration modules were old (oddly, since I did `composer require..` just an hour ago). I updated them with:

```
composer require drupal/migrate_plus:4.0-beta3 drupal/migrate_tools:4.0-beta3 drupal/migrate_upgrade:3.0-rc4
drush cr

```

and now I do get some migrate commands, but not the `migrate-upgrade` command I need.

```
% drush list | grep migrate
 migrate:
   migrate:status (ms)                        List all migrations with current status.
   migrate:import (mim)                       Perform one or more migration processes.
   migrate:rollback (mr)                      Rollback one or more migrations.
   migrate:stop (mst)                         Stop an active migration operation.
   migrate:reset-status (mrs)                 Reset a active migration's status to idle.
   migrate:messages (mmsg)                    View any messages associated with a migration.
   migrate:fields-source (mfs)                List the fields available for mapping in a source.

```

# Answer
> 1 votes
The final answer was that migrate-upgrade still does not work with drush 9. But, applying the patch on that page does make it work.

The drush `migrate:upgrade` command appears!

# Answer
> 3 votes
Your Migrate Tools and Migrate Upgrade tools have a version not suitable for Drupal 8.5.x. You can see at their web page. For example:

https://www.drupal.org/project/migrate\_upgrade

> ```
> 8.x-3.x: This branch works with Drupal 8.2.x and above.
> 8.x-2.0: This release works only with Drupal 8.1.x. This release is no longer supported.
> 8.x-1.0: This release works only with Drupal 8.0.x. This release is no longer supported.
>
> ```

And https://www.drupal.org/project/migrate\_tools:

> ```
> 8.x-4.0-beta2+ - Compatible with Drupal 8.3.x and above and Drush 8/9, this is where primary development will be focused.
> 8.x-3.0-rc1 - Compatible with Drupal 8.2.x only, support for major/critical bug fixes only.
> 8.x-2.0 - Compatible with Drupal 8.1.x only, no longer supported.
> 8.x-1.0 - Compatible with Drupal 8.0.x only, no longer supported.
>
> ```

Then, you should update both:

```
composer require 'drupal/migrate_tools:^4.0'

composer require 'drupal/migrate_upgrade:^3.0'

```

And clear drush cache:

```
vendor/bin/drush cc drush

```

Not sure if a Drupal cache rebuit is needed (drush cr)

After it, you can see your migrate commands in the drush command list:

```
vendor/bin/drush list

```

---
Tags: drush, migrations, composer
---


title: Updating core to a newer version

text:
# Question
Title: Updating core to a newer version
I can update Drupal 7 websites core with following instruction from "How to update Drupal core".

1. Make a backup of your Drupal instance (database). (For ex: with MySQL)
2. Download the latest release of your current Drupal version.
3. Extract the \[tar ball or zip\] Drupal package.
4. Set your site on maintenance mode (For ex: How on D7)
5. Delete all the files & folders inside your original Drupal instance except for /sites and its sub-folders. This assumes that all of your custom work - including themes - is in the recommended spot - the /sites folder tree. If you have made custom changes elsewhere you will need to either preserve them or plan to replace them later.
6. Copy all the folders and files except /sites from inside the extracted Drupal package \[tar ball or zip package\] into your original Drupal instance location.
7. Some updates do not include changes to setting.php and some do. See There is a way - Comment below for more on this. If the update release includes changes to settings.php you will need to replace your old settings.php in .../sites/default/ with the new one, and then edit the site-specific entries (eg database name, user, and password) in the setting file.
8. If you have modified files such as .htaccess or robots.txt re-apply those changes to the new files.
9. If you have a favicon.ico file that was deleted replace it too
10. Login to your site as administrator or as user no 1
11. Run update.php by navigating to http://...yourdrupalsitename/update.php and follow the process to update your Drupal instance
12. Disable maintenance mode

I want to know the instruction for updating Drupal 8 core (e.g. from 8.0.0 to 8.0.2). How do I do it?

# Answer
> 11 votes
1. Download drupal 8.0.2
2. Extract
3. Copy the core directory into your project.
4. Copy the .htaccess , composer.lock & composer.json files to your project
5. Copy the vendor directory to your project
6. Go to yoursite.com/update.php
7. Follow the on-screen instructions

Note: if you use composer then see my answer to this question

# Answer
> 7 votes
Instead on doing such long and hectic procedure it better to learn and update drupal 8 core through DRUSH.

**1. Install Drush for Drupal8.**

**2. Put your site in maintenance mode through drush.**

```
 drush sset system.maintenance_mode 1

```

**3. Run update command in drush to start update.**

```
drush pm-update

```

**4. Put your site online again**

```
drush sset system.maintenance_mode 0

```

# Answer
> 0 votes
This page on drupal.org is actually not bad: https://www.drupal.org/docs/8/update as well as the overview of options linked from there: https://www.drupal.org/docs/8/update/options

I imagine pages in that section have been updated quite a bit since this question was originally posted.

What is confusing is that there are so many ways to update core: manual, drush, composer. Also there are some "gotchas" that I do not see mentioned, such as Drush version 8.1.15 (or higher - but not 9 yet) is needed for 8.4.x and higher.

When I started with Drupal around 2007, you did not need any command line stuff and Composer was not around yet. But today developers really need to be comfortable with command line, and the sooner you get comfortable with Composer, the better. That makes a steeper learning curve for newbies for sure, although you can still install Drupal the same way you did with all previous versions, so one can get at least started that way.

There are lots of blog posts on Drupal & Composer. Jeff's are my favorites: https://www.jeffgeerling.com/blog/2017/tips-managing-drupal-8-projects-composer

Note: I see above "5. Copy the vendor directory to your project". I would not do that as it will wipe out anything in the vendor folder that got put there for modules added. Instead, copy/paste the contents of the vendor folder, replacing or adding to the contents of your current vendor folder.

---
Tags: 8, updating
---


# Question
Title: What is the correct core update workflow?
I want to use composer to manage Drupal 8 dependencies, but I'm not sure what is the right core update workflow. At the moment I'm using drush to update core to latest beta release, but I also have some dependencies in my composer.json file, so after the update I'm using composer install to install all the contrib vendor dependencies. It appears that running `composer install` overrides some files in the core directory, although I've just updated core to latest version.

I've also tried to manually edit the composer.json file and replace the "drupal/core" line with the specific beta release, e.g. `"drupal/core": "~8.0-beta14",`, but it still overrides files in the core directory.

What is the right workflow?

# Answer
> 11 votes
I presume that you are using drupal-composer/drupal-project as the basis for your project. If not, take a look at that project, and compare it with yours.

Also, you said that you want to use composer to manage Drupal 8 dependencies, so I presume that you have selected your contrib modules via `composer require drupal/devel` rather than `drush dl devel`.

If you are doing all of these things, then you should use `composer update` to update Drupal core and all of your contrib modules. As long as you retain your `composer.lock` file, `composer install` should not change the version of any of your dependencies. You should not use `drush pm-update` at all. It should not matter to you whether or not files in the `core` directory are updated or not, as this directory is managed by Composer. You are better off not committing composer-managed directories to your repository, although you can if you wish.

Of course, you should run `drush updatedb` whenever `composer update` replaces Drupal core or any module.

To avoid getting development versions, set your minimum stability to 'beta' in your composer.json file using Composer stability flags.

If you are using drupal-composer/drupal-project to manage your site, then all of the root-level files such as README.txt, .htaccess and index.html become owned by your project. That means that you should check them in to your git repository; Composer will not update them, you must update them yourself when they change. These files should change only rarely, but drupal-composer/drupal-project has a script to update these files.

# Answer
> 2 votes
Yes, you can manage Drupal core with composer. There are a couple of things to be aware of though.

You will probably get timeouts due to a number of items composer has to run through, especially if you run in a local VM. If you run `composer install` you will likely get the composer error:

```
 [RuntimeException]
  Could not delete core/.nfs0000000000000000000001:

```

Make sure you use require

```
{
  "require": {
   "drupal/core": "8.3.*"

```

Also add an extension to the timeout in the config

```
    "installer-paths": {
        "core": ["type:drupal-core"],
        "modules/contrib/{$name}": ["type:drupal-module"],
        "profiles/contrib/{$name}": ["type:drupal-profile"],
        "themes/contrib/{$name}": ["type:drupal-theme"],
        "drush/contrib/{$name}": ["type:drupal-drush"],
        "modules/custom/{$name}": ["type:drupal-custom-module"],
        "themes/custom/{$name}": ["type:drupal-custom-theme"]
    }
},

"config":{
            "process-timeout": 1600
       },

```

Also if that does not work you can run composer install **from outside SSH in your VM**.

This will bypass any NFS share timeouts and unpack Drupal in the right place.

# Answer
> 2 votes
The following is OK for patch releases **8.4.x \> 8.4.y**, but not OK for minor releases **8.4.x \> 8.5.x**. Jump to **UPDATE 3** below for what I believe is "the answer" for minor release updates.

1- Backup any files that come with Drupal which you have modified, such as .htaccess, robots.txt, etc. (those 2 are the most commonly changed).

2- \[I am told delete lock file is wrong, see UPDATE below\] ~~Delete the **composer.lock** file (in the top level folder of your site). This gets recreated in step 5.~~

3- Check your **composer.json** (in the top level folder of your site) and make sure that the "drupal:core" is in the require section and not in a replace section, for example

```
"require": {
"drupal/core": "^8.4"
},

```

not

```
"replace": {
"drupal/core": "^8.4"
},

```

If "drupal/core" is in the replace section, move it to the require section and delete the replace section. If there are other entries in the replace section, just remove the "drupal/core" not the entire replace section - but I think "drupal/core" is normally the only thing there.

Put what version you want to update to in "drupal/core", examples:

"drupal/core": "^8.5" - will update to the latest version of 8.5. "drupal/core": "8.4.6" - will update to version 8.4.6.

5- Run this (in the top level folder of your site):

```
composer update drupal/core --with-dependencies

```

6- If no errors, then do the usual, run the updates and clear cache:

```
drush updatedb
drush cr

```

Or if not using drush, go to /update.php to run updates, then to admin/config/development/performance and hit the "Clear all caches" button.

7- If you had backed up files in the first step (.htaccess, robots.txt) put them back. But check to see if Drupal made updates to those files and add those changes to yours.

DONE

If there were errors with the composer update in step 5, it is usually due to issues with versions of the stuff in the vendor folder.

This is a great post in dealing with such issues: https://www.jeffgeerling.com/blog/2018/updating-drupalcore-composer-drupal-core-doesnt-update and read Jeff's other 2 posts on Drupal and Composer to get more knowledge about that.

I was told by 2 people on Twitter that composer.lock should not be deleted (Step 2 above). The `composer update drupal/core --with-dependencies` command recreates the lock file anyways.

In testing this method I find it works fine for 8.4.3 \> 8.4.6 (for example) but I get errors for 8.4.6 \> 8.5.x. Will report back when I figure it out.

Example of errors:

```
Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - symfony/yaml 3.4.x-dev conflicts with symfony/console[v3.2.8].
    - symfony/yaml 3.4.x-dev conflicts with symfony/console[v3.2.8].
    - symfony/yaml 3.4.x-dev conflicts with symfony/console[v3.2.8].
    - drupal/core 8.5.0 requires symfony/yaml ~3.4.5 -> satisfiable by symfony/yaml[3.4.x-dev].
    - Installation request for drupal/core 8.5.0 -> satisfiable by drupal/core[8.5.0].
    - Installation request for symfony/console (locked at v3.2.8, required as ~3.2.8) -> satisfiable by symfony/console[v3.2.8].

```

This post by Jeff Geerling addresses similar issues, but so far no luck for me: https://www.jeffgeerling.com/blog/2018/updating-drupalcore-composer-drupal-core-doesnt-update

So... the only thing that seems to work for me for 8.4.x \> 8.5.x is the "nuclear option" that so many others seem to use, which is run `composer update`.

I guess that is OK so long as you are sure about the module versions in composer.json. Maybe one should lock them down to the current version. For example:

```
"drupal/address": "1.3"

```

rather than:

```
"drupal/address": "^1.3"

```

**But is the the right answer?**

OK the answer that seems to be everywhere is to do the "nuclear option":

**A. Delete the `/vendor` folder.**

**B. Run `composer update` and simply update your modules along with core. Or, lock down the module versions in `composer.json` if you don't want to update them.**

One person on Drupal Slack said *"the whole philosophy of Composer is that you should always be updating packages, as frequently as possible"*. Packaged includes modules I think. So it makes some sense I guess.

Once I got from 8.4.6 to 8.5.0, this worked fine to get from 8.5.0 to 8.5.1 `composer update drupal/core --with-dependencies` just as it did for 8.4.3 to 8.4.6.

I am starting to conclude that "the answer" is that deleting the vendor folder and the composer.lock file, then using `composer update` is fine, and that one should simply make sure the version numbers for dependencies in the composer.json file are what you want. It's not that big a deal to manage what module versions you want to keep or allow to update in `composer.json`.

For example:

`"drupal/admin_toolbar": "1.18",` means stick with 1.18

`"drupal/admin_toolbar": "^1.18",` means go ahead and update but within 1.x (not 2.x)

This is backed up by a comment (General Redneck) on this post: https://www.jeffgeerling.com/blog/2018/updating-drupalcore-composer-drupal-core-doesnt-update *"One of the things I've found as I work in support is that locking down the versions of modules and core is a good idea so that you CAN thermonuke the thing when you want because there are times when some of the various plugins even don't want to behave correctly."*

By the way, the composer.lock file is no help with `composer update` because it gets blown away (as opposed to `composer install` where he lock file is read):

Running `composer install` will:

* Check if a `composer.lock` exists
* If not, perform a `composer update` to create one
* If `composer.lock` exists, install the specified versions from the lock file

Running `composer update` will:

* Check `composer.json`
* Determine the latest versions to install based on your version specs
* Install the latest versions
* Update `composer.lock` to reflect the latest versions installed

Ref: https://www.engineyard.com/blog/composer-its-all-about-the-lock-file

I see this is mentioned above: https://github.com/drupal-composer/drupal-project. I have used that and it's fine but it is not a requirement for using Composer with Drupal. It is confusing as it sort of "sounds" like it is from the name. When I first started with Drupal 8 I thought it was required, so built my first D8 site with that, thinking it was best practice.

That "version" of Drupal has he docroot in a /web folder, not in the top folder of the project. Also there is a bunch of stuff added to .gitignore compared to normal Drupal:

```
/drush/contrib/
/vendor/
/web/core/
/web/modules/contrib/
/web/themes/contrib/
/web/profiles/contrib/
/web/libraries/

```

So, this version of Drupal is really more meant for sites which are using continuous integration to do a new build of Drupal on every deploy, using composer install. If you deploy with a more normal method, you obviously have to commit all the above stuff to your git repo or it will not get deployed to your server \[1\], and that stuff is all needed for Drupal to run.

\[1\] if git is involved with your deploy - if you deploy with SFTP, ignore this.

# Answer
> 1 votes
Using the drupal/core package on packagist.org we can actually manage the core, the contrib modules (, themes and profiles) and the other vendors via composer.

I've setup the following files in my root directory and executed `composer install`

## composer.json

```
{
  "require": {
    "composer/installers": "^1.0.20",
    "drupal/core": "8.0.*"
  },
  "extra": {
    "installer-paths": {
      "core": ["type:drupal-core"],
      "modules/contrib": ["type:drupal-module"],
      "profiles/contrib": ["type:drupal-profile"],
      "themes/contrib": ["type:drupal-theme"]
    }
  },
  "scripts": {
    "post-install-cmd": [
      "./post_install.sh"
    ]
  }
}

```

## post\_install.sh

```
#!/usr/bin/env bash
export RAW_DRUPAL="https://raw.githubusercontent.com/drupal/drupal/8.0.x"
curl $RAW_DRUPAL/example.gitignore > example.gitignore
curl $RAW_DRUPAL/.gitattributes > .gitattributes
curl $RAW_DRUPAL/.htaccess > .htaccess
curl $RAW_DRUPAL/.csslintrc > .csslintrc
curl $RAW_DRUPAL/.editorconfig > .editorconfig
curl $RAW_DRUPAL/.eslintrc > .eslintrc
curl $RAW_DRUPAL/.eslintignore > .eslintignore
curl $RAW_DRUPAL/index.php > index.php
curl $RAW_DRUPAL/update.php > update.php
curl $RAW_DRUPAL/web.config > web.config
curl $RAW_DRUPAL/autoload.php > autoload.php
curl $RAW_DRUPAL/robots.txt > robots.txt
mkdir -p sites/default
curl $RAW_DRUPAL/sites/example.sites.php > sites/example.sites.php
curl $RAW_DRUPAL/sites/development.services.yml > sites/development.services.yml
curl $RAW_DRUPAL/sites/example.settings.local.php > sites/example.settings.local.php
curl $RAW_DRUPAL/sites/default/default.services.yml > sites/default/default.services.yml
curl $RAW_DRUPAL/sites/default/default.settings.php > sites/default/default.settings.php

```

Enjoy :)

# Answer
> 0 votes
"drupal/core": "~8.0-beta14" means any release greater than 8.0-beta14 and less than 9! You'll want to remove the tilde to lock it to a specific release. Then make sure to update your lock file by running composer up, and on the target system use composer install.

An easy way to get started is to build the codebase using https://github.com/drupal-composer/drupal-project.

When we need to update something such as upgrading core, you run "composer up" locally. This will update the composer.lock file.

When other developers pull down, or in a deployment script, you would run "composer install", which uses the lock file.

The line in our composer.json for Drupal core is:

```
"drupal/core": "~8.0",

```

The tilde () means any release within the 8 number (but not 9).

If you want to lock it to a specific version, you shouldn't use the tilde.

```
"drupal/core": "8.0-beta14",

```

then run "composer up" locally, commit the composer.json and composer.lock file, and then run "composer install" on other installations after pulling down the codebase.

---
Tags: 8, updating, composer
---


title: How do I update core to 8.5?

text:
# Question
Title: How do I update core to 8.5?
After I realized that the thing I mostly enjoyed using Drupal for the last 10 years, Drush, is being axed, I started to set up all new Drupal sites with Composer. Unfortunately I can't update core as I supposed to do it, as `composer update drupal/core --with-dependencies` leads to the following messages.

```
Package "drupal/core" listed for update is not installed. Ignoring.
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
Drupal\Core\Composer\Composer::preAutoloadDump
Drupal\Core\Composer\Composer::ensureHtaccess

```

The content of the composer.json file is the following.

```
{
    "name": "drupal/drupal",
    "description": "Drupal is an open source content management platform powering millions of websites and applications.",
    "type": "project",
    "license": "GPL-2.0+",
    "require": {
        "ckeditor/autogrow": "4.7.2",
        "ckeditor/fakeobjects": "4.7.2",
        "ckeditor/image": "4.7.2",
        "ckeditor/link": "4.6.2",
        "codemirror/codemirror": "5.27.4",
        "composer/installers": "^1.0.24",
        "drupal/background_image_formatter": "^1.3",
        "drupal/backup_migrate": "^4.0@beta",
        "drupal/bg_image_formatter": "^1.0@beta",
        "drupal/bootstrap": "^3.6",
        "drupal/checklistapi": "^1.6",
        "drupal/clientside_validation": "^1.0@RC",
        "drupal/contact_storage": "^1.0@beta",
        "drupal/crop": "^1.3",
        "drupal/ctools": "^3.0",
        "drupal/ds": "^3.1",
        "drupal/entity_clone": "^1.0@alpha",
        "drupal/field_group": "^1.0",
        "drupal/honeypot": "^1.27",
        "drupal/image_effects": "^2.0",
        "drupal/image_url_formatter": "^1.0@beta",
        "drupal/image_widget_crop": "^2.1",
        "drupal/layout_plugin": "^1.0@alpha",
        "drupal/linkit": "^4.3",
        "drupal/metatag": "^1.3",
        "drupal/path_alias_xt": "1.x-dev",
        "drupal/pathauto": "^1.0",
        "drupal/piwik": "^1.2",
        "drupal/redirect": "^1.0@beta",
        "drupal/single_page_site": "^1.4",
        "drupal/sitemap": "^1.3",
        "drupal/social_media_links": "^2.6",
        "drupal/spamspan": "^1.0@alpha",
        "drupal/taxonomy_menu": "^3.3",
        "drupal/token": "^1.0",
        "drupal/video": "^1.2",
        "drupal/views_arg_order_sort": "1.x-dev",
        "drupal/views_bootstrap": "^3.0",
        "drupal/views_field_view": "^1.0@beta",
        "drupal/webform": "^5.0@beta",
        "drupal/webform_views": "^5.0@alpha",
        "drush/drush": "^8.1",
        "jquery/geocomplete": "1.7.0",
        "jquery/icheck": "1.0.2 ",
        "jquery/image-picker": "0.3.0",
        "jquery/inputmask": "3.3.7",
        "jquery/intl-tel-input": "12.0.0",
        "jquery/rateit": "1.1.1",
        "jquery/select2": "4.0.3",
        "jquery/timepicker": "1.11.11 ",
        "jquery/toggles": "4.0.0",
        "jquery/word-and-character-counter": "2.5.1",
        "progress-tracker/progress-tracker": "1.4.0",
        "signature_pad/signature_pad": "2.3.0",
        "wikimedia/composer-merge-plugin": "^1.4"
    },
    "replace": {
        "drupal/core": "^8.4"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "preferred-install": "dist",
        "autoloader-suffix": "Drupal8"
    },
    "extra": {
        "_readme": [
            "By default Drupal loads the autoloader from ./vendor/autoload.php.",
            "To change the autoloader you can edit ./autoload.php.",
            "This file specifies the packages.drupal.org repository.",
            "You can read more about this composer repository at:",
            "https://www.drupal.org/node/2718229"
        ],
        "merge-plugin": {
            "include": [
                "core/composer.json"
            ],
            "recurse": false,
            "replace": false,
            "merge-extra": false
        },
        "installer-paths": {
            "core": [
                "type:drupal-core"
            ],
            "modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "drush/contrib/{$name}": [
                "type:drupal-drush"
            ],
            "modules/custom/{$name}": [
                "type:drupal-custom-module"
            ],
            "themes/custom/{$name}": [
                "type:drupal-custom-theme"
            ],
            "libraries/{$name}": [
                "type:drupal-library"
            ]
        }
    },
    "autoload": {
        "psr-4": {
            "Drupal\\Core\\Composer\\": "core/lib/Drupal/Core/Composer"
        }
    },
    "scripts": {
        "pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
        "post-autoload-dump": [
            "Drupal\\Core\\Composer\\Composer::ensureHtaccess"
        ],
        "post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
        "post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup"
    },
    "repositories": {
        "0": {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        "ckeditor.autogrow": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "ckeditor/autogrow",
                "version": "4.7.2",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "ckeditor.autogrow"
                },
                "dist": {
                    "url": "https://download.ckeditor.com/autogrow/releases/autogrow_4.7.2.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "ckeditor.fakeobjects": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "ckeditor/fakeobjects",
                "version": "4.7.2",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "ckeditor.fakeobjects"
                },
                "dist": {
                    "url": "https://download.ckeditor.com/fakeobjects/releases/fakeobjects_4.7.2.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "ckeditor.image": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "ckeditor/image",
                "version": "4.7.2",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "ckeditor.image"
                },
                "dist": {
                    "url": "https://download.ckeditor.com/image/releases/image_4.7.2.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "ckeditor.link": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "ckeditor/link",
                "version": "4.6.2",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "ckeditor.link"
                },
                "dist": {
                    "url": "https://download.ckeditor.com/link/releases/link_4.6.2.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "codemirror": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "codemirror/codemirror",
                "version": "5.27.4",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "codemirror"
                },
                "dist": {
                    "url": "https://github.com/components/codemirror/archive/5.27.4.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "jquery.geocomplete": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "jquery/geocomplete",
                "version": "1.7.0",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "jquery.geocomplete"
                },
                "dist": {
                    "url": "https://github.com/ubilabs/geocomplete/archive/1.7.0.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "jquery.icheck": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "jquery/icheck",
                "version": "1.0.2 ",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "jquery.icheck"
                },
                "dist": {
                    "url": "https://github.com/fronteed/icheck/archive/1.0.2.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "jquery.image-picker": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "jquery/image-picker",
                "version": "0.3.0",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "jquery.image-picker"
                },
                "dist": {
                    "url": "https://github.com/rvera/image-picker/archive/0.3.0.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "jquery.inputmask": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "jquery/inputmask",
                "version": "3.3.7",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "jquery.inputmask"
                },
                "dist": {
                    "url": "https://github.com/RobinHerbots/jquery.inputmask/archive/3.3.7.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "jquery.intl-tel-input": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "jquery/intl-tel-input",
                "version": "12.0.0",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "jquery.intl-tel-input"
                },
                "dist": {
                    "url": "https://github.com/jackocnr/intl-tel-input/archive/v12.0.0.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "jquery.rateit": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "jquery/rateit",
                "version": "1.1.1",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "jquery.rateit"
                },
                "dist": {
                    "url": "https://github.com/gjunge/rateit.js/archive/1.1.1.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "jquery.select2": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "jquery/select2",
                "version": "4.0.3",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "jquery.select2"
                },
                "dist": {
                    "url": "https://github.com/select2/select2/archive/4.0.3.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "jquery.timepicker": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "jquery/timepicker",
                "version": "1.11.11 ",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "jquery.timepicker"
                },
                "dist": {
                    "url": "https://github.com/jonthornton/jquery-timepicker/archive/1.11.11.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "jquery.toggles": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "jquery/toggles",
                "version": "4.0.0",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "jquery.toggles"
                },
                "dist": {
                    "url": "https://github.com/simontabor/jquery-toggles/archive/v4.0.0.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "jquery.word-and-character-counter": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "jquery/word-and-character-counter",
                "version": "2.5.1",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "jquery.word-and-character-counter"
                },
                "dist": {
                    "url": "https://github.com/qwertypants/jQuery-Word-and-Character-Counter-Plugin/archive/2.5.1.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "progress-tracker": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "progress-tracker/progress-tracker",
                "version": "1.4.0",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "progress-tracker"
                },
                "dist": {
                    "url": "https://github.com/NigelOToole/progress-tracker/archive/v1.4.0.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "signature_pad": {
            "_webform": true,
            "type": "package",
            "package": {
                "name": "signature_pad/signature_pad",
                "version": "2.3.0",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "signature_pad"
                },
                "dist": {
                    "url": "https://github.com/szimek/signature_pad/archive/v2.3.0.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        }
    }
}

```

Googling around I found many tips, but neither worked.

https://www.drupal.org/forum/support/upgrading-drupal/2018-02-01/update-to-850-through-composer-failure suggests to remove the vendor and core directories and run what didn't do the trick for me. Someone else suggests `composer require drupal/core:8.5.1` which I didn't try, because it might work, but what sense would it make to add every release as a dependency, and this is what it means, right?

Why does "composer update drupal/drupal" not work? describes a similar issue. I couldn't make sense of the answers, but it may be that I lack the secret knowledge you need, to understand composer and Drupal 8.

https://www.drupal.org/forum/support/upgrading-drupal/2017-10-06/update-to-84-with-composer is a very long thread. It's hard to say what you should try, and what is too risky. Somebody says:

> I was only able to update to 8.5.0 by manually changing the composer file:
>
> `drupal/core": "^8.5`
>
> and then running composer update --with-dependencies

Really? Do I have to edit the composer.json file before I can update? Is that the way to go?

Somebody else says:

> `"require”: {
>  "drupal/core": "^8.4"
>  },`
>
> not
>
> `"replace": {
>  "drupal/core": "^8.4"
>  },`

Is this the way to go? But why is the core than under replace in the first place?

This is so frustrating! I find myself downloading zip files deleting folders and extracting other only to update Drupal 8, where before the only thing I had to do was running `drush up drupal`.

Can somebody help me?

# Answer
> Really? Do I have to edit the composer.json file before I can update? Is that the way to go?

The composer.json file specifies what packages/modules in which version you want to have installed.

So the general answer is, depending on what it contained, changing it is exactly what you need to do. See https://getcomposer.org/doc/articles/versions.md. To be able to update to 8.5, you need to tell composer that it is a valid version.

However, You only use drupal/core if you have a composer-based project, aka one that started based on https://github.com/drupal-composer/drupal-project/. If you just download a tarball from drupal.org then you have drupal/drupal and not drupal/core and I don't know if that can be updated with composer then.

My recommendation would be to start a new project based on drupal-project, then re-add all the dependencies you want and any custom module/theme that you had added. The only real difference is that now drupal itself and all the public files are in the web/ folder. That is more secure and allows to have varous things that should not be public in easily in the repository, like documentation, (behat) test. From then on, updating should be as easy as running composer update, as long as your version constraints allow an update.

> Drush, is being axed,

The only part of drush that is "axed" is drush make, drush itself is definitely still around and maintained.
> 3 votes

---
Tags: 8, updating, composer
---


# Question
Title: What is the best way to update Drupal periodically using a cron job?
Previously I periodically updated Drupal sites by using a cron-job with a "drush up -y" script running every Wednesday 15,16,17,18,19,20,21,22 hours UTC. which is when "Security releases happen" according to https://www.drupal.org/node/1173280

Lately I noticed that when security issues are really urgent, the update can take place just any time during the week. I now let the update cron take place every hour every day. I am aware this is not an ideal solution. What is the better solution to update Drupal with a cron script say within the hour of any release?

# Answer
> How can we automate our updates when these exceptions take place?

Updates are not automatic. The update manager module will tell you (in the admin) when critical updates or updates are available for core or contributed modules. But nothing will automatically update it all for you. You can also have the system email you when updates are found, too - per site. This is also helpful for staying informed.

You could theoretically "auto update" with a CI/build workflow that builds X times per day, but there is more inherent risk there of breaking the site unless you are strict about versions of contrib, and specify `drupal/core` as `~8.0` and minimum stability stable. Though, that is not bulletproof. In the last update from 8.4 to 8.5, I had to patch over a contrib module due to a change introduced in core. That contrib module still has not updated to comply with the change. If I had this sort of workflow, core would have updated and broke the site. That isn't so much the fault of core, but the contrib module(s) not keeping pace with the changelog or the sometimes unfortunate BC breaks.

While auto update sounds like a good idea, its usually not worth the mentioned risk. I prefer to clone locally and run through the application to see if anything has changed, moved, or flat out broke instead of have it hit production immediately. I think most would agree.

With this latest PSA, everyone was given a weeks notice that it was coming so people could prepare and plan their release window around it. So there should have been plenty of time to stay informed, and most hosting companies (i.e.: ones who promote Drupal) should have notified their customers.

Wednesday is when the Security Team makes public any security issue on covered third-party modules.
> 1 votes

---
Tags: updating, security
---


title: How do I disable user pictures?

text:
# Question
Title: How do I disable user pictures?
In Drupal 7, you can disable user pictures just by unchecking the appropriate box on the Config -\> People screen.

How can I disable user pictures in Drupal 8? I see that the default D8 install adds an image field `user_picture` at `/admin/config/people/accounts/fields`, but I assume that it would be better to somehow disable this than just to delete it.

For now, I don't want user pictures to be shown or used in any way, unless I decide to re-enable them later.

# Answer
If you don't want to delete the field, you can exclude the field from input:

```
/admin/config/people/accounts/form-display

```

and from output:

```
/admin/config/people/accounts/display

```
> 8 votes

# Answer
I am using the Field Permissions module to accomplish this by only lettings admins see the field. This way I do not disrupt what is there by default if things change in the future.
> 3 votes

---
Tags: users, 8
---


# Question
Title: Why is access to some of my product displays denied for anonymous users?
I think I have some database corruption and a number of commerce display nodes have have become access denied for anonymous users. I am not using any access control modules and the problem persists even after allowing anonymous users to bypass content access control. Clearly there is something badly wrong.

I have clear caches etc, to no avail.

What could be causing this and were should I start looking for a fix?

Following the suggestions given in comments, I have tried rebuilding permissions and this does not help.

# Answer
> 1 votes
I have the same problem. It\`s because product entity was unpublished. After publishing entity all warks correct.

---
Tags: commerce
---


# Question
Title: What if update.php fails due to code errors?
I sometimes run into the issue, when my PHP code has errors. I run update.php, but it fails with a php error message. After that, Drupal seems to think that the database is up-to-date, but it isn't. Trouble is, running update.php again does not solve the problem.

For example, just now, it has failed to create the tables for a newly created entity. update.php does nothing, but all my Entity code – of course – fails with database errors.

I don't know how to recover from this situation, other than uninstalling and reinstalling the module, which means killing all content first.

# Answer
> 1 votes
You could also rerun the update after you fixed your code.

See here: reseting the hook\_update\_n status of a module

---
Tags: entities, database
---


# Question
Title: Ability to only allow certain content to be added between a range of dates
I have a drupal 7 site that is used for registration for certain events. We are currently using content types to collect the information. What I need is to only allow registered users to post certain content types between a certain set of dates. Certain roles should be able to add/edit at any time.

For example. One of the content types is Grant. But we only accept grants between May 1 and May 31st.

Before May 1st we'd like to have a message that states: Grants are currently not open, please check back May 1st. After May 31st we'd like a message to state: Grants are currently closed for Spring 2018, please try again next year. or something like that.

# Answer
> 1 votes
I would suggest looking into the Rules module for this.

Using this module, you can use its Condition feature to:

* Check the date ranges that you specified
* Check what content type is being created
* Check the current logged in user's role if it's the permitted user role to create a content type

Based if these conditions are met, you can then add what event or message for this matter to display to the user. You aren't also limited to creating one rule but you can create multiple rules based on your conditions.

Hope this gives you an idea and solution.

---
Tags: 7, nodes
---


# Question
Title: D7 Commerce - Save rules applied to line items in cart?
I want my users to be able to redeem points for discounts off of their orders. Every dollar is worth 20 points. I've managed to work the entire equation in Rules to line items, however none of the rules I put into place save. Here is what I have so far:

As soon as I leave my cart, the value changes from the discounted value I've set, back to 0.00. For some reason, the updated unit price will not save (even though I've set it to?) Am I missing something? Apologies for crazy rule, but it's the only way I could get it done.

**Update:** I've learned that Cart Refresh is the reason rules applied to line items in cart don't save. How can I make these rules stick?!

# Answer
> 0 votes
I don't think there is. You will have to:

1. Add a Discount `/admin/commerce/discounts`, which will generate a discount rule. `/admin/config/workflow/rules?event=0&tag=Commerce%20Discount`
2. Edit the discount Rule and do your magic here.
3. Create a Coupon `/admin/commerce/coupons` and link it to your Discount in the "Discount Reference" field.

---
Tags: 7
---


title: Unable to Update to latest core

text:
# Question
Title: Unable to Update to latest core
Update from 8.5.0 to 8.5.1 is failing on one of my drupal instance.

```
>composer update drupal/core --with-dependencies
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package symfony/debug (locked at v4.0.6, required as ^3.4.0)
 is satisfiable by symfony/debug[v4.0.6] but these conflict with your
requirements or minimum-stability.

```

What does this mean? What should I do?

PS: Please find below some more related information

```
>composer outdated
consolidation/output-formatters       3.1.13       3.2.0
dflydev/dot-access-data               v1.1.0       v2.0.0
drupal/core                           8.5.0        8.5.1
drupal/metatag                        1.4.0        1.5.0
egulias/email-validator               1.2.14       2.1.3
guzzlehttp/guzzle                     6.3.0        6.3.2
nikic/php-parser                      v3.1.5       v4.0.1
psy/psysh                             v0.8.17      v0.8.18
symfony-cmf/routing                   1.4.1        2.0.3
symfony/config                        v3.4.6       v4.0.6
symfony/console                       v3.4.6       v4.0.6
symfony/dependency-injection          v3.4.6       v4.0.6
symfony/event-dispatcher              v3.4.6       v4.0.6
symfony/filesystem                    v3.4.6       v4.0.6
symfony/finder                        v3.4.6       v4.0.6
symfony/http-foundation               v3.4.6       v4.0.6
symfony/http-kernel                   v3.4.6       v4.0.6
symfony/process                       v3.4.6       v4.0.6
symfony/routing                       v3.4.6       v4.0.6
symfony/serializer                    v3.4.6       v4.0.6
symfony/translation                   v3.4.6       v4.0.6
symfony/validator                     v3.4.6       v4.0.6
symfony/var-dumper                    v3.4.6       v4.0.6
symfony/yaml                          v3.4.6       v4.0.6
twig/twig                             v1.35.2      v2.4.7

```

composer.json file:

```
    "name": "drupal/drupal",
    "description": "Drupal is an open source content management platform powering millions of websites and applications.",
    "type": "project",
    "license": "GPL-2.0+",
    "require": {
        "composer/installers": "^1.0.24",
        "wikimedia/composer-merge-plugin": "^1.4",
        "drush/drush": "^9.2",
        "drupal/ctools": "^3.0",
        "drupal/devel": "^1.2",
        "drupal/ds": "^3.1",
        "drupal/conditional_fields": "^1.0@alpha",
        "drupal/field_group": "^1.0",
        "drupal/filefield_paths": "^1.0@beta",
        "drupal/bootstrap_layouts": "^5.1",
        "drupal/page_manager": "^4.0@beta",
        "drupal/page_manager_ui": "^4.0@beta",
        "drupal/magnific_popup": "^1.3",
        "drupal/config_update": "^1.5",
        "drupal/config_update_ui": "^1.5",
        "drupal/duration_field": "^1.1",
        "drupal/pathauto": "^1.1",
        "drupal/token": "^1.1",
        "drupal/metatag": "^1.4",
        "drupal/bootstrap": "^3.10",
        "drupal/features": "^3.7",
        "drupal/admin_toolbar": "^1.23",
        "drupal/linked_field": "^1.1",
        "drupal/core": "^8.5",
        "drupal/bootstrap_paragraphs": "^2.0@beta",
        "drupal/entity_reference_revisions": "^1.4",
        "drupal/paragraphs": "^1.2",
        "drupal/eva": "^1.3",
        "drupal/slick_views": "^1.0@RC",
        "drupal/yaml_editor": "^1.0"
    },
    "replace": {
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "preferred-install": "dist",
        "autoloader-suffix": "Drupal8"
    },
    "extra": {
        "_readme": [
            "By default Drupal loads the autoloader from ./vendor/autoload.php.",
            "To change the autoloader you can edit ./autoload.php.",
            "This file specifies the packages.drupal.org repository.",
            "You can read more about this composer repository at:",
            "https://www.drupal.org/node/2718229"
        ],
        "merge-plugin": {
            "include": [
                "core/composer.json"
            ],
           ],
            "recurse": false,
            "replace": false,
            "merge-extra": false
        },
        "installer-paths": {
            "core": [
                "type:drupal-core"
            ],
            "modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "drush/contrib/{$name}": [
                "type:drupal-drush"
            ],
            "modules/custom/{$name}": [
                "type:drupal-custom-module"
            ],
            "themes/custom/{$name}": [
                "type:drupal-custom-theme"
            ]
        }
    },
    "autoload": {
        "psr-4": {
            "Drupal\\Core\\Composer\\": "core/lib/Drupal/Core/Composer"
        }
    },
    "scripts": {
        "pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
        "post-autoload-dump": [
            "Drupal\\Core\\Composer\\Composer::ensureHtaccess"
        ],
        "post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
        "post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup"
    },
    "repositories": {
        "0": {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        "drupal": {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    }
}

```

# Answer
> 0 votes
Try to delete the composer.lock file and try

```
composer update drupal/core --with-dependencies

```

---
Tags: 8, updating
---