Feeds

Author

Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough
Dec 17 2022
Dec 17

Tired of irrelevant search results?

It can be frustrating when users come across search results that should be elsewhere. This is especially true for content you don't want to be indexed to avoid search engines. In Drupal 10, this can happen with nodes marked as "noindex" by the Metatag module.

But fear not! This article will show you a clever solution to this problem.

With a few lines of custom code, you can effectively exclude nodes marked as "noindex" from your Search API results. This will ensure that only the most relevant content shows up, providing a better experience for your users.

Here's a step-by-step guide to getting you started:

Identify the problem: Do you see irrelevant nodes in your search results, even though they are marked as "no index"?

Understand the solution: This article provides a custom code snippet that checks the "metatags" field for the "noindex" value and excludes those nodes from the search results.

Implement the code: Follow the step-by-step instructions in the article to add the code to your Drupal website.

Following these steps, you can say goodbye to irrelevant search results and keep your users happy!

Dec 16 2022
Dec 16

Question: I have two content types that have the same fields. For certain nodes, I would like to convert from one node type to another. How can I accomplish this?

Reply: Where custom_node_type would make the necessary determination based on the node source data whether to return 'page' or 'policy'.

Dec 04 2021
Dec 04

Sometimes during development, we need to completely remove all users from the site, for example, when you copy a site for another project or work with migration.

For these purposes, we can use modules such as Entity Delete.

However sometimes more quickly just use custom code in your custom module or install devel_php and run with admin interface on /devel/php.

Dec 04 2021
Dec 04

This article is out of date. See a more recent article for a better solution.

In a project where we use the Search API to search for content, we noticed that nodes that are marked as "noindex" by the Metatag module are visible during internal searches.
Here is a ready-made solution for how to avoid this.
Perhaps hook_entity_update() is more suitable here instead of hook_cron(), however, for our implementation with many existing nodes, we decided to implement it through cron.
Everyone has a good time of the day.
Do not forget to leave a comment on how you implemented it.

Jan 27 2021
Jan 27

When you try to uninstall a module that has a field that you have used, it can throw the following error:

The following reasons prevent the modules from being uninstalled: Fields pending deletion

In my case, it was when I tried to disable the "Comment" module. This is an issue that can happen in both Drupal 8 and Drupal 9. This is due to the fact, that Drupal doesn’t actually delete data for the field when you delete the field. It deletes the data during cron runs. If cron hasn’t been run enough times since you deleted the field, drupal won’t let you uninstall the module.

To force drupal to purge the data, you can run the following command

drush php-eval  'field_purge_batch(1000);'

You can also use an user interface provided by devel_php module.

Increase 1000 to a high enough number to wipe out the data, or run a few times. After this has completed, you should be able to uninstall the module.

References:
Module uninstall dependencies
The message "Required by Drupal (Fields Pending Deletion)"
Can’t uninstall YAML because of the following reason: Fields pending deletion

Oct 04 2020
Oct 04

Retrieving the image URL from an image field in Drupal 8 and 9 seemed pretty straightforward too. Even the solution for getting the image style URL from a simple image field can be found quite easily. Getting the image URL from a media field can also be looked up easily.

Apr 13 2020
Apr 13

The "Update Manager Advanced" module very similar to "Update Status Detailed Email", however, implemented in another way and available for Drupal 10.

This module modifies the Drupal "Available updates" email report to include the information normally shown at /admin/reports/updates/update, with links to the module updates and their release notes.

It can be helpful, for example, in case, if you received the mail and see that only one module was updated and this module uses on the admin interface only and nothing critical for the visitors and updating can wait. So you shouldn't spend time in opening the site for checking.

Link to the module: https://www.drupal.org/project/advupdate.

Apr 13 2020
Apr 13

Since starting from Drupal v8.8.0 has removed the Wikimedia merge plugin and replaced it with a Composer 'path' repository, a native Composer feature which serves the same needs as the merge plugin with fewer disadvantages, in this short article, I want to show how to manage dependencies for a custom project.

Create composer.json file with a similar code:

{
    "name": "mypackage/custom_module",
    "description": "The description of my module.",
    "type": "drupal-custom-module",
    "homepage": "https://makedrupaleasy.com",
    "authors": [
        {
            "name": "Ruslan P",
            "homepage": "https://www.drupal.org/u/ruslanp",
            "role": "Maintainer"
        },
    ],
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "preferred-install": "dist"
    },
    "require": {
        "symfony/dom-crawler": "^4.0",
        "symfony/css-selector": "^4.0"
    }
}

Find the repositories section of your root composer.json file, and modify it to include your custom module or modules as path repositories:

"repositories": [
    {
        "type": "composer",
        "url": "https://packages.drupal.org/8"
    },
    {
        "type": "path",
        "url": "docroot/modules/custom/custom_module"
    }
]

Next, require your module in your project: composer require mypackage/custom_module

Done!

Related links:

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web