DDD: delete tree “Node” should check for children

I have a tree of Installations: Aggregate Installation has a property ParentInstallationId.

I also have a RemoveInstallationCommand –> repo.GetInstallation(x).Remove()

Now, I want to throw a domain error if I receive a RemoveInstallationCommand for an Installation that has children. But, the Installation aggregate doesnt know about its children, its the other way around.

So, is it ok to query the command model for children, and throw if count > 0?

If not, how would you solve this?

Node form that defines fields based on another node

I have two content types (Unit and Scheme of Works). In Unit, I have a field (field_lo) that allows the user to create an unlimited number of entries.

In Scheme of Works, I need to associate other field values related to the field_lo entries from Unit. Effectively, in Scheme of Works, I need to be able to dynamically add a number of fields to match the quantity of the field_lo entries in Unit.

Is this possible? If so, how?


Cerrar Sesión Automaticamente en Json Web Tokkens Node Js

Muy Buenos dias Comunidad recurro a ustedes para que me puedan ayudar con Las sesiones JWT en Node.js actualmente este es mi codigo

let verificaToken = (req, res, next) => {      let token = req.cookies.token;      jwt.verify(token,process.env.SEED, (err, decoded) => {          if (err) {             res.redirect("/");             return         }          req.usuario = decoded.usuario;         next();      });  }; 

y si cierra sesion pero no me lo redirecciona cuando caduca el tiempo del Jwt que esta en 1 hora (60*60) en mis api’s lo utlizo así

app.get("/busqueda-proveedor/:nombre", [verificaToken, verificaAdmin_Role], (req, res) => {      let nombre = req.params.nombre;      consultaSQL(`SELECT * FROM proveedores WHERE nombre LIKE '%$  {nombre}%'`)     .then(result => {          if (result.length <= 0) {              return res.json({                 ok: false,                 mensaje: "Lo sentimos no se ha encontrado ningun proveedor"             })          }          res.json({             ok: true,             data: result         })       })     .catch(err => console.log(err)) }) 

cuando la Sesión caduca y se hace una busqueda manda errores en la consola y tengo que refrescar la pagina para que recien me mande al login

How to disable cration of node revision on programaticall node update ($node->save())?

I added a field of type computed field to existing nodes. It’s required to re-save the nodes to set/update computed field values. As I do not want to update the changed timestamp I decided to not use the views bulk update to resave content. The easiest way would be a drush script, that way I can re-save content whenever it is necessary.

My first problem was that I was not able to leave the changed time unchanged on update ($ node->save()). But I found that it could be re-set on a second node save.

My problem is that on each node save a new revision gets created. The node type is revision-able and beside the core module content moderation is enabled. I would appreciate any help on how to prevent the creation of revisions.

This is my current drush script in custom_helper.drush.inc:

<?php /**  * @file  * Provides drush command to update all articles.  */  use Drupal\node\Entity\Node;  /**  * Implements hook_drush_command().  */ function custom_helper_drush_command() {   $  items = array();   $  items['custom-resave-content'] = array(     'description' => dt('Resaves all article entities.'),     'options' => [       'types' => dt('Coma separated list of content type to be resaved.'),       'nids' => dt('Coma separated list if node ids.'),       'field' => dt('Machine name of computed field to be updated.')     ],     'aliases' => array('custom-rc'),   );   return $  items; }  /**  * Moves paragraphs into one paragraph reference field.  */ function drush_custom_helper_custom_resave_content() {   $  nids = _convert_csv_to_array(drush_get_option('nids', []));   $  types = _convert_csv_to_array(drush_get_option('types', []));    if (!$  nids || $  types) {     // Get an array of node IDs.     $  query = \Drupal::entityQuery('node');     if ($  types) {       $  query->condition('type', $  types, 'IN');     }     if ($  nids) {       $  query->condition('nid', $  nids, 'IN');     }     $  nids = $  query->execute();   }    // Load all the nodes.   if ($  nids) {     $  field_name = drush_get_option('field', '');      $  nodes = Node::loadMultiple($  nids);     foreach ($  nodes as $  node) {       $  entity_type = $  node->getEntityType();       $  original_changed = $  node->getChangedTime();       if ($  entity_type->isRevisionable()) {         $  node->setNewRevision(FALSE);       }       if ($  field_name) {         /** @var \Drupal\Core\Field\FieldItemListInterface $  items */         $  items = $  node->get($  field_name);         if (empty($  items[0])) {           $  items->appendItem();         }         $  items->preSave();       }        $  node->setChangedTime($  original_changed);       if ($  entity_type->isRevisionable()) {         $  node->setNewRevision(FALSE);       }       $  node->save();        $  node->setChangedTime($  original_changed);       if ($  entity_type->isRevisionable()) {         $  node->setNewRevision(FALSE);       }       $  node->save();        $  changed_after = $  node->getChangedTime();       drush_print('node:' . $  node->id() . ':' . $  original_changed . ':' . $  changed_after);     }   }    drush_log(dt('Resave finished.'), 'ok'); } 

How to get entity field value with the Node content?

I have two content types Artist and Artist Type, And in the artist content type, I have created the entity field for artist Type. I have created the 4 nodes for the artist type artist type 1,artist type 2, artist type 3,artist type 4.During the creation of artist node I have selected the one from all artist type. Also, I have created the Artist type of view and shown the information according to the contextual filter: ID. But not getting an idea of how to get the value of all node title value of artist content type in the artist type node preview page?

How to show menu items depending on the user’s roles and the node type?

I would like to show some menu items (merged with the main navigation menu) when viewing a node (full content) of a custom content type. Also, this menu items depend on user’s roles. It could be something like contextual menu, but with the main menu. For example, I have a custom content type “invoice” and when an user is viewing an invoice, some new menu items should be shown, like “send by email”, “pay”,…

Heartbeat node that was kicked out doesn’t rejoin virtual IP service

We have a 2-node heartbeat cluster that servers a virtual IP. Previous due to an error, the network interface for node1 died and resulted in the cluster kicking node1 from the virtual IP party.

Now that we have fixed it, node1 no longer gets to rejoin the virtual IP party. Setting node2 to standby does not trigger failover to node1.

I am unfamiliar with heartbeat. Is there a configuration/command anywhere that allows me to reverse/configure/un-blacklist this?

Redirect to custom error page if node submit fails validation

I’ve embedded a node/add form on my homepage for submissions but for caching purposes, I need to have any server-side validation occur on a different page instead of itself.

I.e. If the form fails server-side validation, it returns me to the index page. INSTEAD, I’d like it to go to some other page, like /form-error and display the error there with the form below to fix the error.

How can I print the vocabulary name instead of the referenced term in a node template?

Let’s say I have a content type article with a field “taxonomy”.

The vocabulary is “fruits”.

The terms are “apple”, “orange”, “bananas”

The article belongs to “orange”.

I can easily print in my twig template the term of the article :

{{ content.field_taxo_fruit }} 

Result is “orange”.

But I don’t find an easy way to print the vocabulary : “fruits”.

On an other project, I used views field and I used “rewrite result”. But here, I use twig template like node--article--teaser.html.twig

Send mail notification when node of given type gets created

Use case: a small site where I want to warn all users by mail whenever a new content of a particular type is created. I thought I would try Rules+Actions to handle this.

I’m working on a vanilla Drupal 8 test site on my workstation, so there is just “Article” and “Basic Page”.

I’ve installed the Rules module ok. I’ve looked at several videos explaining how this works in Drupal 7 and they looked reasonable straightforward. Now I’m trying to do something in D8 and finding it less than obvious.

Specifically, I’ve created the rule to fire when new content is created, and now I’m on a page editing Condition, where I want to specify that the node type is “Article”. Using “Data selection” mode in the “Entity” field I select “node.type”. This seems logical, but what on earth do I put in “Type”? No matter what I put I get a message something like this: “Data selector node.entity for context Entity is invalid. Unable to apply data selector ‘entity’ at ‘entity’ ” – which is about as unexplicit as you can get.

Maybe I’m jumping the gun and Rules is not usable yet? Or maybe I’ve just not understood it at all…

But I would really appreciate if somebody could explain to me what seems quite straightforward in principle. How do I add a condition to my Rule that will cause the rule to fire only on a specific content type?