Drupal StackExchange

How to modify a paragraph behavior setting programmatically?

1 day 13 hours ago

I would like to alter/change a certain paragraph behavior plugin setting.

If I debug the paragraph entity, I can find the behavior_settings value, but it's json encoded and I don't think the best option is to decode it, change the values, encode it again and then assign it back to the paragraph, there must be a much better way.

Alejandro

Change default format for date field on user register form

1 day 13 hours ago

I'm new to Drupal 8. In the user registration form, i've added a Date field via manage fields in user account settings. However, I need to customize this field and change its format. I tried 'manage display' but it's not taking effect. Is there something I'm missing. (Ideally, it should look and behave just like field datetime in Drupal 8 webform)

Appreciate any help given.

Thanks

ram_griever

How do I get the price of a line item for the transactions which are already completed?

1 day 14 hours ago

There are some transactions which are made using drupal commerce module along with commerce ccavenue module. I have the order ids, transaction ids and list of line items purchased in each of the orders. But the problem is I if a product price is updated in past then I am not able to find the cost of the product in the past order when the product was purchased.

Is there any place where drupal stores product price for a particular order anywhere.

user24595

How to rebuild images using Imagemagick?

1 day 15 hours ago

I have switched the Image toolkit from GD2 to Imagemagick. It’s working great for new images, however previously uploaded images still show up with lowres quality.

How can I regenerate ALL images using Imagemagick?

I've followed up: Rebuild images from image style

  • drush: drush image-flush mystyle
  • rm -rf sites/default/files/styles
  • Clearing Caches a couple of times and hit save on all image styles.

However all images still show up with lowres quality. When I manually update a node, the image quality looks correct. Also, the file size changes. Looks like imagemagick isn’t triggered. What can I do?

user32010

How override theme for a node add\edit form?

1 day 18 hours ago

I'm on D10.2.x. My site uses Gin as back-end theme but also as fallback front-end, being decoupled and having to "front-end page" actually shown via Drupal.

I'd want to override the default node add\edit form for some extra html markup. As I can't just override via a *.twig template in the theme folder, I'm trying with a module.

I've tried wit the code\example from e.g. How do I theme a custom form? or https://makedrupaleasy.com/articles/drupal-10-how-render-any-form-twig-template

My code is the following:

my_module.module:

/** * Implements hook_theme(). */ function my_module_theme($existing, $type, $theme, $path) { return [ 'my_custom_form_twig' => [ 'variables' => [], 'render element' => 'form', ], ]; } /** * Implements hook_form_alter(). */ function my_module_form_alter(&$form, FormStateInterface $form_state, $form_id) { //removed temporarily the check on $form_id $form['#theme'][] = 'my_custom_form_twig'; }

/templates/my-custom-form-twig.html.twig

{{ dd() }} <h1>MY CUSTOM TWIG</h1> <form{{ attributes }}> {{ children }} </form>

dump result

array:13 [▼ "form" => [] "theme_hook_original" => "my_custom_form_twig" "attributes" => Drupal\Core\Template\Attribute {#1517 ▶} "title_attributes" => Drupal\Core\Template\Attribute {#1738 ▶} "content_attributes" => Drupal\Core\Template\Attribute {#1515 ▶} "title_prefix" => [] "title_suffix" => [] "db_is_active" => true "is_admin" => true "logged_in" => true "user" => Drupal\Core\Session\AccountProxy {#1404 ▶} "directory" => "themes/contrib/gin" "theme_hook_suggestions" => [] ]

However this doesn't work, as I'm facing two issues:

  1. As a test, I've checked that the override works for most forms on the site, as they are replaced with my custom twig. However, the node edit\add forms still use the original one, so I suppose some extra logic is done by the Node module and I need to do something more to override it, but I don't know\can't find what.
  2. As shown by the dump of my twig (in the other places of site), the form array is actually empty. There is also no element or children object so I can't rely on them as fallback. Therefore my twig can't actually print the form.

Thank you for suggestion on either of the two problems.

Giuseppe

Drupal Planet

DrupalEasy: cspell and drupalorg CLI: two useful tools for Drupal contrib module maintainers

1 day 15 hours ago

While preparing the recent Markdown Easy 1.0.1 release, I utilized a couple of tools that I hadn't used before in order to help improve code quality as well as the quality of the release notes.

cspell

cspell is a Node.js spell-checker for code that was made available to the default Drupal GitLab templates in February, 2024. There is a new SKIP_CSPELL variable that can be set if you'd like your project to completely ignore cspell (it is enabled by default.) Documentation on using cspell in Drupal GitLab pipelines is available. I'd wager that most Drupal contrib maintainers will have the need for a custom word list (as I did,) so I took a few minutes to learn a bit more about it.

Cspell uses its default wordlist along with a few add-on dictionaries related to Drupal development (anecdotally, words like "mglaman," "gloop," "skynet," and "vampirize" are included) for checking the spelling of both variable names as well as code comments, but luckily, additional words (and patterns) can be added on a per-project basis in order to achieve a clean cspell report in GitLab pipelines. While there are several methods to add a list of custom words, the way I felt was most elegant (and easy for me to remember in the future!) was to add a .cspell-project-words.txt file on the project root (in this case, the contrib module is the project.) This file then includes a list of words that cspell should not flag as misspellings. For the Markdown Easy project, I went with "Anello," "~commonmark," and "~ultimike" (possibly for obvious reasons.) The ~ modifier indicates those words are case-insensitive (additional modifiers are available.) With that change, Markdown Easy now earns a passing score from the cspell pipeline. 

drupalorg CLI

drupalorg is a command-line interface maintained by (who else?) Matt Glaman. I actually learned about this tool a few years ago after Matt blogged about it, but for whatever reason, I only thought about installing and (finally) using it recently. The general idea is to provide a command line tool for contributors to interact with drupal.org. It's available commands are:

help Displays help for a command list Lists commands cache cache:clear (cc) Clears caches ci drupalci drupalci:list (ci:l) Lists test results for an issue drupalci:watch (ci:w) Watches a Drupal CI job issue issue:apply Applies the latest patch from an issue. issue:branch Creates a branch for the issue. issue:interdiff Generate an interdiff for the issue from local changes. issue:link Opens an issue issue:patch Generate a patch for the issue from committed local changes. maintainer maintainer:issues (mi) Lists issues for a user, based on maintainer. maintainer:release-notes (rn, mrn) Generate release notes. project project:issues (pi) Lists issues for a project. project:kanban Opens project kanban project:link Opens project page project:release-notes (prn) View release notes for a release project:releases Lists available releases tci travisci travisci:list (tci:l) Lists Travis Ci builds for a Drupal project travisci:watch (tci:w) Watches a Travis CI job

The maintainer:release-notes command is especially helpful to automatically generate release notes for a new version of a Drupal contrib project. Here's how I installed and used this tool to generate the release notes for Markdown Easy 1.0.1:

  1. I downloaded the drupalorg.phar to a new ~/sites/drupalorg/ directory on my local, and renamed the file to just drupalorg.
  2. I then gave execute permission to this file via chmod u+x ~/sites/drupalorg/drupalorg
  3. I use zsh, so I added the following to my ~/.zshrc file and then restarted my terminal:

    # drupalorg command line tool export PATH="/Users/michael/sites/drupalorg:$PATH"
  4. Here's the important part - I then navigated to my local, working copy of the Markdown Easy module. In my case cd ~/sites/d10/web/modules/contrib/markdown_easy 
  5. I then ran the following command to generate the release notes: drupalorg maintainer:release-notes 1.0.0  

I assumed at first that I should use the current release (1.0.1) as the argument, but after reading the documentation, I discovered that the command will generate release notes from the tag provided in the argument.

I also originally assumed that the command would take a contrib module's machine name as an argument, but after a few minutes of poking around the documentation, I realized that the command must be run from the module's directory.

You can see the automatically generated release notes here.

Summary

Both of these tools were rather easy to implement (once I read just a little bit of documentation) and seem like they'll be useful for just about any Drupal contrib maintainer. 

qtatech.com blog: Drupal 9 to 10 Transition Made Simple: Real Code Insights

1 day 18 hours ago
Drupal 9 to 10 Transition Made Simple: Real Code Insights kanapatrick Tue, 04/23/2024 - 10:31

Have you found yourself gearing up for the transition from Drupal 9 to Drupal 10, only to be met with complexities and uncertainties along the way? You're not alone in this journey. Making the switch between major versions of a CMS can feel like navigating through a maze of code and updates, leaving you puzzled and overwhelmed.

Specbee: Improving Drupal SEO: How to Fix Duplicate Content with the Global Redirect Module

1 day 20 hours ago
As a content writer, one thing that poses a serious concern for professionals in this field is plagiarism. It refers to the act of using someone else’s work and calling it your own. It can be frustrating and is ethically and legally unacceptable. Duplicate content is no less than plagiarism. In fact, it can cause concerns not only for content professionals but also for website owners and SEO professionals. Surprisingly, 25-30% of the content on the internet today is duplicated without people even realizing it. In this blog, we’ll talk about duplicate content, the significance of this issue in today’s metrics, and how Drupal helps you solve the problem with convenience. What is duplicate content Duplicate content simply means identical content that exists across various URLs on the internet. When identical content shows up on different URLs, search engines typically face confusion in determining which URL to prioritize in their search results. This leads to low-ranking issues for all the URLs that display similar content, while preference slides over to alternative web pages. Why is it a significant problem As mentioned earlier, duplicate content can cause issues for marketers, website owners, and SEO professionals. Let me categorize the types of issues it can bring you: For Search Engines Identification: Search engines struggle to determine which version(s) of content to include or exclude from their indexes. Link Metrics Distribution: They face uncertainty in distributing link metrics like trust, authority, anchor text, and link equity among multiple versions or a single page. Ranking Ambiguity: It becomes unclear which version(s) should rank for specific search queries. For Website Owners Search Engine Optimization: To enhance user experience, search engines tend to display only one version of duplicated content. This reduces the visibility of all duplicates. Link Equity Dilution: Inbound links are divided among duplicates rather than consolidating on one page. This disperses the link equity, affecting the search visibility of the content piece. Consequently, duplicated content fails to achieve the search visibility it could otherwise attain. What causes duplicate content Now that you’ve gathered some information about the seriousness of the issue of duplicate content, here are a few potential and technical causes that lead to content duplication. URL Parameters: This issue arises when you apply URL parameters or tracking in your website’s code. According to Google, these URL variations are created by pairing a key and a value which are separated by an equal sign, and linked by an ampersand. Consequently, although the URLs may seem distinct, users end up on the same page regardless of the link they click. Session IDs: Similar to applied URL parameters, session IDs are assigned different IDs within the URL to each user visiting your site. Multiple Versions of Your Site: This issue arises with websites that have both a www.example.com and an example.com version of their pages. It also applies to sites with an SSL certificate that maintain both HTTP and HTTPS versions of their site. Faceted Navigation: Faceted or filtered navigation allows users to refine details on your site to find the information they are looking for. It enables them to customize their search experience. However, search engines may perceive these filtered URL results as duplicated content. Types of duplicate content Duplicate content affects your SEO ranking. Having said that, in terms of search engine optimization, duplicate content is of two different types:    1. Site-wide/Cross-domain Duplicate Content Site-wide duplicate content occurs when identical or similar content is available across different pages within the same website or across multiple domains. For instance, some e-commerce platforms may use similar product descriptions on their primary domain (store.com), mobile version (m.store.com), or localized domain versions like store.ca. Such duplication of content challenges your SEO ranking.  If the duplicate content extends beyond a single website to multiple websites, determining the organic search result becomes a challenging task, requiring specific strategies to deal with the same.    2. Copied Content/Technical Problems This sounds like an oversight yet a major issue at that. Such duplicate content occurs from directly copying content to multiple locations or due to technical issues that result in the display of similar content on various URLs. This may be the case with URLs with parameters lacking canonical tags, duplicate pages without the no index directive, and copied content published without proper redirection.  When canonical tags or redirects are not appropriately set up, search engines may index and attempt to rank nearly identical versions of pages, leading to potential SEO complications. How Can Google Help Detect Duplicate Content One of the most popular and verified methods of assessing duplicate content is by simply selecting a few words from the site, enclosing them within quotes, and inputting them into Google search.  Ideally, this test on any page from your website should show your webpage in the search results, without other entries. However, if other websites also appear along with yours, Google considers the top results to be the original source of content. If you don’t find your webpage on top of the results, it might be a concern of duplicate content. You can repeat this procedure by testing several short, random sentences from your webpage using Google. Additionally, there are various free tools to check for duplicate content over the web, such as Copyscape, Plagspotter, Duplichecker, Smallseotools, and more. The Global Redirect Module: Fixing Duplicate Content SEO Issues in Drupal For those who’re unaware, Drupal is an open-source content management system that works towards simplifying development and creation processes for its global community. It offers many core and contributed modules that serve its purposes. One such module works towards fixing the issue of duplicate content - the Global Redirect Module.  The Global Redirect module is an SEO-friendly module that offers you a user-friendly interface to manage your URL path redirects. In Drupal, the alias system can sometimes lead to duplicate URLs, which can affect your website's search engine ranking. This Drupal module tackles this issue by checking for existing aliases and redirecting to the correct URL. Additionally, it manages URL formatting by removing trailing slashes, ensuring clean URL usage, and verifying node permissions and access. As per the module’s documentation source, here’s what it does to correct/fix duplicate content: Verifies if the current URL has an alias and performs a 301 redirect to it if it's not currently in use. Checks for a trailing slash in the current URL, then removes it if found, and repeats the first check with the updated request. Determines if the current URL matches the site's front page and redirects to the front page if there's a match. Ensures that Clean URLs are enabled and confirms whether the current URL is accessed using the clean method rather than the unclean method. Validates access to the URL; if the user lacks access to the path, no redirects occur. This feature helps protect private aliased nodes from exposure. Enforces the case sensitivity of the accessed URL to match the one set by the author/administrator. In non-technical interpretation of the above information, the Drupal Global Redirect module  Establishes fresh redirects. Detects faulty URL paths (ensure the “Redirect 4040” sub-module is activated for this feature). Configures redirects at the domain level (utilize the “Redirect Domain” sub-module for this purpose). Imports existing redirects. This way, you avoid the risk of having the very same content displayed on multiple URL paths. How to Configure the Global Redirect Module Before you configure the module, make sure to download it from https://www.drupal.org/project/globalredirect and then proceed with the following steps to configure the module to fix the issue of duplicate content on your Drupal site: Navigate to the Configuration page in your Drupal dashboard. In the Search and Metadata section, click on the URL redirects option. If you don’t find it, try clearing your Drupal cache and check again. On the URL redirects page, find the list of created redirects. Click on the +Add redirect button to add a new redirect. In the Path field, enter the old title or URL alias that you want to redirect from. In the To field, specify the relative internal path or the absolute external path that you want the old URL to redirect to. Choose the appropriate Redirect status from the drop-down menu. Click on Save at the bottom of the page to save the redirect configuration. Navigate to the Settings tab at the top of the page to access additional configuration options for the Global Redirect module. In the Settings tab, modify the default redirect status and adjust global redirect settings as needed.Click on Save Configuration to apply the new settings. Final Thoughts To wrap up, duplicate content affects your search engine rankings and impacts user experience as well as link equity distribution. It poses threatening challenges for content creators, website owners, and SEO professionals. Understanding the causes and types of duplicate content can help devise effective strategies to fix this issue. In Drupal, the Global Redirect module offers a convenient solution to manage URL redirects and prevent duplicity of content. While there are many other ways to boost your SEO ranking, Drupal users trust this module to work best in fixing duplicate content issues. It ensures clean URLs, proper redirection, and improved SEO performance on your Drupal site. So, employ effective measures to rank your Drupal website - avoid duplicate content, stick with Google algorithms, stay up-to-date with the latest technological measures, or you could connect with an expert Drupal development agency to enhance your Drupal SEO and boost your site’s search engine ranking.