Skip to main content
3 votes
Accepted

Is it logical to give a homepage an alias?

Drupal core allows to have multiple paths for the same node. In the case of a node assigned as a homepage and with an alias there are at least three paths to access the node. / /node/123 /my-alias ...
4uk4's user avatar
  • 100k
3 votes
Accepted

How to access the node/term field-values in a cleaner way?

You can use magic getter methods like $entity->field_name->database_column to get the first value of a field: $node->field_name->value; $node->field_entity->target_id; $node->...
Hudri's user avatar
  • 5,539
2 votes

How can I copy a field to another field?

You can run this, in hook_update_N(): $storage = \Drupal::entityTypeManager()->getStorage('node'); // Load all the nodes IDs for nodes that don't have the new value set. $nids = $storage->...
Jaypan's user avatar
  • 17.6k
2 votes

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "node_type" plugin does not exist

Search your config files and replace every occurrence of id: node_type With id: entity_bundle:node Import updated config and clear caches, and it should work.
Webdrips's user avatar
  • 742
2 votes

How can I get a printable version of a node?

Use the Printer and PDF versions module.
mona lisa's user avatar
  • 5,929
2 votes
Accepted

How to have a different hero image per node?

You are asking for a better solution, this would be a hero block instead of hard-coding the hero image in the page template. If your block is using the node route context it automatically loads the ...
4uk4's user avatar
  • 100k
2 votes

Which is the correct way to create redirects from existing nodes

I am afraid is a no black & white answer here and you're both right. It really comes down to your needs, use case and budget. The redirect module will automatically create that redirect for you if ...
No Sssweat's user avatar
  • 31.4k
1 vote

How to get the title of a referenced entity with `?_format=json`?

JSON:API returns ID, UUID, and URL because that's the spec. If you want more properties, like the title or the content body, you have to include those. See the documentation on includes. Also two ...
Patrick Kenny's user avatar
1 vote

How can I generate multiple pages, each with a unique URL based off of 1 template?

I doubt having so many pages with mostly the same content would be great for SEO, but you do you. An easy and obvious way to do that with Drupal is to create a Taxonomy for locations where each term ...
prkos's user avatar
  • 7,151
1 vote
Accepted

How get the default language of a translatable node bundle?

Snippet code: to get the default langcode defined in the settings form: (Drupal 9/10) use Drupal\language\Entity\ContentLanguageSettings; // Get the default langcode that selected in the entity's ...
mini_poojasharma's user avatar
1 vote
Accepted

How can I avoid a node is crawled and indexed by search engines in the tightest way possible?

Yes, Drupal has a mechanism to block all crawlers in the “tightest way possible”: authentication.
mona lisa's user avatar
  • 5,929
1 vote
Accepted

How can I embed PHP code in HTML?

In answer to the questions you asked: No this will not work. Drupal 9 uses the Twig templating engine. You cannot execute arbitrary PHP code in Twig. Instead you should write a Drupal module.
mona lisa's user avatar
  • 5,929
1 vote

Why isn't an image from the local domain shown with the explanation that, for security reasons, only images from the local domain are allowed?

I solved this by re-ordering the filters, so tracking is done before the Restriction check. Track images uploaded via a Text Editor Restrict images to this site* Image Resize Filter: Resize images ...
NickStees's user avatar
  • 111
1 vote

user_cancel_reassign() doesn't work when user has more than 10 nodes

In my case, I was performing mass user deletion in a Drush command. First I was calling directly the batch operation _user_cancel because calling user_cancel() was leading to perform a batch in a ...
romain ni's user avatar
  • 837
1 vote

Cloning nodes between multisite instances with separate databases

this module does it all! it's awesome! https://www.drupal.org/project/single_content_sync
JannaAus's user avatar
1 vote

How to restrict access to some nodes based on roles or users?

This is a few years old but I thought I would throw in an answer on how to do this with a very light weight custom module. This answer would be applicable to Drupal 8, 9, and 10. I am using Drupal 8 ...
serverjohn's user avatar
1 vote

Update a field without changing the node

The functionality is available on SqlContentEntityStorage but it's protected. Bother! said Pooh and reflected on his poor Drupal coding practices: $storage = $this->entityTypeManager->...
̷c̷h̷x̷'s user avatar
1 vote

Display Suite ignores hook_preprocess_node()

I was able to trigger it using hook_preprocess_ds_entity_view(): function mytheme_preprocess_ds_entity_view(&$variables) { $variables['node'] = $variables['content']['#node']; $variables['...
Dave Nattriss's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible