8 – Retrieve the last published version of the node (moderation status) when making the transition to the publication

I am looking forward to getting the latest published revision of a node that has a status of "published" content moderation. The following code works fine until I configure a node in the "published" state where it can not find anything.

                $ query = Drupal :: database () -> select (& # 39; content_moderation_state_field_data & # 39 ;, & # 39; ms & # 39;);

$ query-> join (& # 39; node_field_revision & # 39 ;, & # 39; nf & # 39 ;, & # 39; nf.nid = ms.content_entity_id AND nf.vid = ms.content_entity_revision_id AND nf.langcode = ms. langcode & # 39;);

// Join the table so we can verify what type of content this node is an entity.
$ query-> join (& # 39; node_field_data & # 39 ;, & # 39; nd & # 39 ;, & # 39; nd.nid = nf.nid & # 39;);

$ query-> fields (& # 39; nf & # 39 ;, ['nid', 'vid']);

// Compare the moderation states in the workflow of the site.
$ query-> condition (& # 39; ms.workflow & # 39 ;, & # 39; site_content & # 39;);

// The node must be in a moderation state published in the site workflow.
$ query-> condition (& # 39; ms.moderation_state & # 39 ;, $ moderation_state);

// Node content type.
$ query-> condition (& # 39; nd.type & # 39 ;, $ bundle_id);

returns $ query-> execute () -> fetchAll ();

How can I get this to return the last published version of a node when the status changes to published?

This code is called by a service called from hook_entity_type_update ().

How to add a pager to the TOP of a forum in Drupal 8?

I am using the standard forum module that comes with Drupal 8. The problem is that when I see a forum node, it shows the pager at the bottom. I want the pager to also appear at the top.

The closest I could come is to edit the template "comment – comment_forum.html.twig". If I put random text on top of this template, I can see the text that appears in the correct place I want. But if I put this:


Then nothing is shown. So the comment – comment_forum.html.twig template does not know what "pager" is.

Does anyone know where the right place is to add a pager to the top of the forum posts?

8 – How to add an additional eventlistener to the menu object in the attached library

This is my first Drupal 8 project and I have a problem to discover how to attach an additional event handler to an object.
I'm working on a custom theme using Radix as a base theme. I'm using Superfish as a menu module.
One of the problems is that Superfish creates a menu & # 39; root & # 39; additional call & # 39; Menu & # 39; that is displayed when you click on the menu of the Bootstrap burger. Afterwards, you must click on & # 39; Menu & # 39; to show the real menu (accordion).
I found a snippet of code in a problem: https://www.drupal.org/project/superfish/issues/2891228 that hides the & # 39; Menu & # 39; option, but I can not make it work.

I have configured a library definition and created a & # 39; script.js & # 39;

import "popper.js";
import "bootstrap";

(function ($, Drupal) {
Drupal.behaviors.helloWorld = {
attach (context) {
console.log ("Hello World");

Drupal.behaviors.myMainMenu = {
attach (context) {
console.log ("myMainMenu:" + context.toString ());
$ (". navbar-collapse", context) .once (& # 39; myMainMenu & # 39;). in (
"shown shown.bs.collapse show.bs.collapse",
() => {
console.log ("navbar-collapse");
if (! $ ("# superfish-main-accordion"). hasClass ("sf-expanded")) {
console.log (& # 39; not expand & # 39;);
$ (". superfish-main-toggle")
}) (jQuery, Drupal);

I know the script runs, because I see & # 39; Hello World & # 39; and & # 39; myMainMenu & # 39; + Sometimes glob in the console. But I never manage to get the other messages from the console.

I also know that the code in the if statement is correct, because if I execute it manually in the console, it works as expected.

What should be the correct code?

datetime – Drupal 8 Date problem of input format

I need to import a large data set (more than 300,000 records) into a Drupal 8 site. I have discovered how to do this with feeds in a small set of test data.

However, one problem is that the dates in the records have the format "June 8, 2018". I do not see a way to use a Date Drupal 8 field to enter dates in this format.

I need to be able to create views that show records based on a range of dates.

What is the best way to get the data in Drupal in a format that the views can use? Would it perhaps be to use a computed field to transform the data while it is imported? Or would it be better to execute an SQL query once the data is imported?

Thanks for any suggestions.

8 – How to specify the correct path of the private file in a block

I have a Drupal site at http://example.org/xyz

By the instructions here, I have set up a directory of private files outside of the web root.

So let's say the web root is in / home / public_html / example / xyz
The private directory is in / home / public_html / private

I have that private directory configured in the settings.php file and I deleted the caches. It is displayed correctly here: http://example.org/xyz/admin/config/media/file-system

After clearing the cache, I can confirm that there is a valid .htaccess file in / atrium / admin / config / media / file-system

The directory permissions for the private directory are 755.

So now I specify the location of the file of a link in a block like "/xyz/system/myfile.pdf"

When I click on the link, the home page simply reloads (instead of a download window), but the URL now says:

I have tried many other variations, and all fail.

What am I doing wrong?

8 – How is the process of closing the user session supposed to work?

I have built a complete private site. Everything seems to work. When users want to log out, are they redirected from / user / logout / user / login? Destination = /, what appears to be normal behavior, from what I understand.

A client told me that he is not redirected to / user / login? Destination = / but remains in / user / logout, getting an Access Denied error.

I can not reproduce this problem.

How is session closure supposed to work? The redirection of / user / logout to / user / login? Destination = / is the normal behavior?

8 – Upgrade the kernel to a specific version with Composer

My site has not been updated for two months, some new updates have been released.
The main version of my site is 8.5.6.
Before running Composer update - with dependencies I read the notes of the version of the latest version of core (8.6.2), they say:

Sites in 8.5.x should be updated immediately to Drupal 8.5.8 instead, and
plans to update to the latest version 8.6.x before May 2019.

How do I update the old kernel to Drupal 8.5.8 instead?
How do I specify that version in CLI, what command?
Eventually I want to update it to the latest version.

8 – Hook to run afer config import

The configuration system has already changed to events and the event documentation is described in "My first Drupal 8 event subscriber" how to subscribe to a configuration event:


See also this example of the color module:


cacheTagsInvalidator = $ cache_tags_invalidator;

/ **
* Invalidate cache tags when a color theme configuration object changes.
* event @param  Drupal  Core  Config  ConfigCrudEvent $
* The event to be processed.
* /
public function onChange (ConfigCrudEvent $ event) {
// Changing the color settings of a theme causes the subject's resource library
// that contains the color CSS file that will be modified to use a different file.
if (strpos ($ event-> getConfig () -> getName (), & # 39; color.theme. & # 39;) === 0) {
$ this-> cacheTagsInvalidator-> invalidateTags (['library_info']);

/ **
* {@inheritdoc}
* /
Public static function getSubscribedEvents () {
$ events[ConfigEvents::SAVE][]    = ['onChange'];
$ events[ConfigEvents::DELETE][]    = ['onChange'];

returns $ events;


8 – Remove the comment link from the teaser node

firstdirty road In the template links - node.html.twig change this line {% - for key, element in links -%} to {% - for key, element in links if key! = & # 39; comment-add & # 39; and key! = & # 39; comment-forbidden & # 39; -%}. This is to remove the link & # 39; comment-add & # 39; and & # 39; comment-forbidden & # 39; If you also want to delete the number of links, add the line with and key! = & # 39; comment-comments & # 39;. A simpler way to achieve this is to replace all Yess with yes & # 39; comment & # 39; it is not in code. The twig is inside.

The second is the most correct way The point is in using the hook. hook_node_links_alter(Doc). This link will alter the behavior of node links. There is a basic module of comments. It really is worth looking if you want to know how the node comment works. Requires knowledge of drupal module 8. The service responsible for node comment links is comment.link_builder and defined in core / modules / comment / comment.services.yml. And while watching core / modules / comment / src / CommentLinkBuilder.php You may find that you add different links to represent the matrix and all the logic. So the comment is just a module. So let's go back to the hook. Alter the links of the nodes and add comment links. So you need to delete it again. To do this you can define your own module to create a hook. In the module directory you need to create Modulo.module file and place the following code there:

use Drupal  node  NodeInterface;

function kapusta_node_links_alter (array & $ links, NodeInterface $ node, array & $ context) {
unset ($ links['comment__comment']);

Nothing special here, just implementing hook_node_links_alter. The comment link is removed.

The third The road is more elegant but needs more work. It is based on similar things as the second form. The point is to rewrite the service. core / modules / comment / src / CommentLinkBuilder.php. For this you need to define your own module. Next, you will create a service with the name similar to CommentLinkBuilder.php. The symfony (drupal framework being used) will rewrite the service from the comments module. And you will get your benefit. So, first, duplicate the service. For this you create MODULE.services.yml in your modules folder. The content of the file is the following:

class: Drupal  kapusta  CommentLinkBuilder
arguments: ['@current_user', '@comment.manager', '@module_handler', '@string_translation', '@entity.manager']

Where do I get this? Since core / modules / comment / comment.services.yml. I just replaced the class with mine. Then you create that class. You will get the file modules / custom / kapusta / src / CommentLinkBuilder.php With the following content:

<? php

Drupal  Kapusta namespace;

use Drupal  comment  CommentLinkBuilder as Base;
use Drupal  Core  Entity  FieldableEntityInterface;

the CommentLinkBuilder class extends Base {
public function buildCommentedEntityLinks (FieldableEntityInterface $ entity, array, and $ context) {
he came back [];

& # 39; kapusta` is my module name. That is all.

How did I find it? I cleaned variables on the twig. {% - for key, element in links -%}. I discovered the value of key in each iteration. I was commentary-* Keys on which I wrote at the beginning. Then I look for the project files by add comment and found CommentLinkBuilder. With xdebug I got to the hook. Then I realize that it is a simple module. I hope this helps.

8GB of RAM 8 USD | 16GB of RAM 16 USD | 32GB Ram 32 USD | 2XE5-2680 processors | SSD Disk | Unlimited BW |

Hi, Web Hosting Talk members,

Affordable and reliable virtual servers with high performance! We offer you a limited number of servers in the United States.
Thanks to the 1 Gbit network, you can make the upload / download to your liking, you can have a series server performance at the best price for all your needs.

You can order online at any time of the day. Thanks to the control panel, you can perform all the operations, such as restarting, turning on and off at any time. You can request the format at any time, or you may want to install another operating system. You can also get 24/7 support at no charge when you have problems.

Location of the affordable server in the United States
Processors 2X E5-2680 8 CPU
100GB SSD Disk
Unlimited Traffic
Location of USA

Only $ 8 a month. You can click HERE to buy.
16GB ECC Ram
Processors 2X E5-2680 12 CPU
200GB SSD drive
Unlimited Traffic
Location of USA

Only $ 16 a month. You can click HERE to buy.
32GB ECC Ram
Processors 2X E5-2680 16 CPU
400GB SSD drive
Unlimited Traffic
Location of USA

Only $ 32 a month. You can click HERE to buy.

Extra +1 IP only 0.50 USD !!

VDS / VPS packages, hosting of servers, server rental, ddos ​​protection services, protection against domain attacks, bandwidth and cabin rental, rental of servers abroad, etc. we have solutions For more products or projects, you can obtain the solution / service from our website.

Credit card, debit card, prepaid cards, etc. You can pay with cards.
Number of taxes: 7930474989
Tax administration: Beylikdüzü / Istanbul / Turkey
Email: destek@siberdc.com
Phone: +90 850 840 8701
Skype: SiberDC