Drupal StackExchange

Search and Replace URL in database?

2 days 7 hours ago

I need to move a Drupal 9 website to a different server and a lot of links have the old server URL. Normally for Word Press I use this tool - https://github.com/interconnectit/Search-Replace-DB https://interconnectit.com/search-and-replace-for-wordpress-databases/

You upload that to the server and it runs a script to search for your string and replace it with the new string.

I tried to do a regular search and replace in VS Code with -

Search //old.url.com Replace with //new.url.com

It found all the //old.url.com but after I imported the database there are still some links that do not redirect to the new url, one of these is /user. If I go to new.url.com/user it redirects to old.url.com/user

Is there a way to do a search and replace on the database to replace the old URL?

jfc

Migrate Markdown files to Content type

2 days 8 hours ago

I am working on a migrating Markdown files from a repo into my Drupal site and not sure if this is possible. I have created a new content type that is just the title field and the body that accepts Full HTML. The Markdown files would basically be the node on the site and anytime a new file is created or an old one is updated, it would update that node or create a new one after a Cron job is run.

How could I create this kind of migration in Drupal?

ThankYouNeco

The service "redirect.request_subscriber" has a dependency on a non-existent service "path_alias.manager"

2 days 8 hours ago

We have inherited a Multisite Drupal setup and are managing the migration for a client. We have the codebase set up locally and have two of the sites up and running. We are hitting an error on the third though:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The service "redirect.request_subscriber" has a dependency on a non-existent service "path_alias.manager". in Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() (line 86 of /Users/{hidden}/Sites/{hidden}/vendor/symfony/dependency-injection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php).

We're not sure why this error is displaying on this one site and not on the others. Can anyone help please? Drupal core is up to date - running 9.3.12.

Tom Aston

How to send a vote using Advance Poll and Services Voting Api?

2 days 9 hours ago

I need to expose a poll to a mobile app. After doing some research I found out that I could receive the votes, through a web service, using the services_votingapi module, and the go-to poll to use was advpoll, or Advance Poll.

I've made a poll with several choices and added, in a services endpoint, the select_votes and set_votes services for votingapi. What I can't figure out now is how to send a vote using the service? there's some documentation at https://www.drupal.org/node/2145873 but I don't know the correct values to send. How do I know the correct entity ids, etc.?

HaPK

How to validate numbers in a webform custom composite element

2 days 10 hours ago

I have a Webform with a custom composite, and there I have a element which type is Number and i want to validate this element.

If I check required when the field is empty it show a message that the field is required, but if I put letters in the field show the same message when it should be that the field is not valid because it has letters.

I know how to do this with a textfield element but this element is not inside the custom composite with a regular expression . And even if i change the custom composite element from Number to Textfield I can not do it this, can not be validated individually.

Yunior Chacon Sorio

How to get the parent comments (in a custom module)?

2 days 11 hours ago

I'm writing a module that uses flag to handle notifications, and one of the options is to be notified of replies to a given comment.

I can implement without problem hook_comment_publish($comment), but I want to get all of its parent comments so that I can pick up the users that flagged them.

So, how can I retrieve all the parent comments of a given comment (if any)? I noticed that in taxonomy there is a taxonomy_get_parents($tid) but I can't find anything similar for threatened comments.

Antonello

How to set and inherit variables within different twig templates?

2 days 12 hours ago

I'd like to set a variable in my node.html.twig template:

{% set title = label %} {{ content }}

The content consists of one field visible only, which has it's own template:

file-link.html.twig

How can I access the title variable of the node template in the file template? I am not sure if importing or extending is the right way since that might cause infinite recursion?

Edit

The file template looks like this (from the bootstrap theme):

{% spaceless %} {% set classes = [ icon_only ? 'icon-only', not icon_only ? 'icon-' ~ icon_position|clean_class ] %} <span{{ attributes.addClass(classes) }}> {% if icon_only %} <span class="file-icon">{{ icon }}</span> <span class="sr-only"> <span class="file-link">{{ link }}</span> <span class="file-size">{{ file_size }}</span> </span> {% else %} {% if icon_position == 'after' %} <span class="file-link">{{ link }}</span><span class="file-size">{{ file_size }}</span><span class="file-icon">{{ icon }}</span> {% else %} <span class="file-icon">{{ icon }}</span><span class="file-link">{{ link }}</span><span class="file-size">{{ file_size }}</span> {% endif %} {% endif %} </span> {% endspaceless %}

Within that template I'd like to print the title of the respective node:

<span class="file-link">{{ link }}</span> <span class="file-node-title">{{ title }}</span> {# << #} <span class="file-size">{{ file_size }}</span>
Alex

Why does a header set via drupal_set_header() revert to text/html?

2 days 13 hours ago

I'm using the views_rss module in Drupal 6. Whenever I build out a View using this plugin, the following header is sent in a template_preprocess function:

drupal_set_header('Content-Type: application/rss+xml; charset=utf-8');

This seems to be ignored, as the page is ultimately sent with a text/html header. It seems that my header is getting appended, but text/html is either sent first or last (whichever is ultimately interpreted by the browser) and thus has no effect.

How can I force a non-text/html header for a page output in Drupal 6?

Charlie Schliesser

How can I redirect users on login based on their chosen language?

2 days 14 hours ago

I'm looking to redirect users after they login.

The site is multilingual, using English and French.

I've tried using the Login Destination module and using Rules, but it has no options for accessing the language the user has chosen.

On the user edit page, the user can select 'English' or 'French' as their language.

I'm looking, ideally, for a simple rule condition to add, or some PHP.

None of the answers I've found so far have mentioned multilingual sites.

Thanks.

Paul Kerrigan

Cross-domains cookies issue

2 days 14 hours ago

How can I address the challenge of automatic logouts when accessing different subdomains due to cross-domain cookies issues?

How to reproduce: Log in to the a.example.com and then access the b.example.com the cookies_session will be automatically removed.

My Drupal 9 services.yaml below:

parameters: session.storage.options: gc_probability: 1 gc_divisor: 100 gc_maxlifetime: 200000 cookie_lifetime: 2000000 sid_length: 48 sid_bits_per_character: 6 cookie_samesite: Lax cookie_secure: true cookie_domain: '.example.com'

Thanks.

Tuan Hoang