How to include exposed filter name in views data feed export CSV title?

4 days 7 hours ago

Trying to get views data export to save file with selected token from exposed filter

In the settings I can see this explanation:

%exposed == effective exposed filters, like filter1_foo-filter2_bar

So I tried this:

%[field_industry_type].csv %field_industry_type.csv %field_industry_type_tid.csv

But can't get nothing to work, what I'm trying to do is use a field filter as .csv name, one of the filter types is industry, so if industry is "relocation" I would like the file to save like this:

relocation.csv

Maybe my token syntax is wrong?

yvesguy

How to use 'required' and 'optional' states with form api when using a select field?

4 days 8 hours ago

I'm trying to create a form in Drupal 10 that will show an field that is both visible and required depending on the selection of a radio input that comes before it. The visible state seems to work well but for some reason the required and/or optional states do not seem to work on select fields.

public function buildForm(array $form, FormStateInterface $form_state) { $form['field_1'] = [ '#type' => 'radios', '#title' => $this->t('Field 1'), '#options' => [ 'one' => $this->t('One'), 'two' => $this->t('Two') ], '#required' => TRUE, ]; // The field will become invisible but is still required. $form['field_2'] = [ '#type' => 'select', '#title' => $this->t('Field 2'), '#options' => [ 'A' => $this->t('A'), 'B' => $this->t('B'), 'C' => $this->t('C'), 'D' => $this->t('D'), ], '#required' => true, '#states' => [ 'visible' => [ ':input[name="field_1"]' => ['value' => 'two'] ], 'optional' => [ ':input[name="field_1"]' => ['value' => 'one'] ], ], ]; $form['submit'] = [ '#type' => 'submit', '#value' => $this->t('Submit'), ]; return $form; }

When inspecting the HTML you can see that the code for the select is invisible but the required attribute is still present so when you hit submit the form will throw an error. This only happens for select field types as changing the type to textfield/radios seems to work without issues.

blu

How to programmatically clear/refresh module file cache?

4 days 9 hours ago

I'm maintaining a module, and have reworked the file structure of the module to make it more... modular.

In the update functions, some of the new files are referenced, but Drupal isn't aware of the new files until the cache has been cleared. The files are included in the .info file.

Please can someone tell me how to get Drupal to refresh its list of the files in this module?

Thanks,

[Side note - quite surprised that hooks and cache aren't available as tags!]

JohnFF

Change page URL structure based on node field value

4 days 11 hours ago

I'm using Pathauto to produce nice URLs for my Drupal 7 site, and have run into the need to edit the URLs based on a node field value.

Specifically, when the content is archived on my website, the URL needs to be automatically changed to include the substring 'archive'. So when editing this page:

www.mysite.com/mypage

and node:field-status is changed from none to archived, I need the URL to become:

www.mysite.com/archive/mypage

Also, pages that already feature a substring, such as mysite.com/blog/mypage would ideally have the new substring prepended to the relative URL, so:

www.mysite.com/archive/blog/mypage

I have tried using Flags and Rules to rewrite the URL pattern based on the field value, but with no luck. Any ideas?

Timmah

Sort grouping field associated with taxonomy term by weight

4 days 12 hours ago

I'm currently trying to figure out how I can sort the grouping fields(Taxonomy Term) by weight that I have setup on my views.

As shown in this screenshot below I have a grouping field that is associated with a taxonomy term.

  1. Application Deadline
  2. Scholarship Deadline
  3. Class Dates

The only problem is that, it is not sorted accordingly by weight.

Is there a way I could the taxonomy terms by weight. I tried configuring the views but I can't seem to find the solution in solving my problem.

Noel

How do I use the administrative theme?

4 days 13 hours ago

I'm building a custom Drupal theme and wondering if there is a way to get the modal windows to use the default admin theme. I'm using the Layout builder module with a custom block that uses the Media Library module and it uses jQuery UI classes.

This is also for the modal content like the media modal.

Chris Archer

Can't seem to format date in twig from UTC to User's locale

4 days 15 hours ago

I am trying to format the date field from an event content type that I've created so that I can pass the date into an event exporter that creates events in calendars such as Google, Apply, Yahoo, and Microsoft. I use calendar_link which takes a few fields and the dates to create the appropriate calendar event.

{# calendar_link(link_type, title, start_date, end_date, all_day, description, location) #} {% set linkGoogle = calendar_link("google", node.field_event_title.value|raw|replace({'[html format="full_html" different_values="0"]': "", '[/html]': ""})|striptags, date(dateStartField), date(dateEndField), false, "", "") %} {% set linkICS = calendar_link("ics", node.field_event_title.value|raw|replace({'[html format="full_html" different_values="0"]': "", '[/html]': ""})|striptags, date(dateStartField), date(dateEndField), false, "", "") %} {% set linkYahoo = calendar_link("yahoo", node.field_event_title.value|raw|replace({'[html format="full_html" different_values="0"]': "", '[/html]': ""})|striptags, date(dateStartField), date(dateEndField), false, "", "") %} {% set linkWebOutlook = calendar_link("webOutlook", node.field_event_title.value|raw|replace({'[html format="full_html" different_values="0"]': "", '[/html]': ""})|striptags, date(dateStartField), date(dateEndField), false, "", "") %}

This works fine. However, when I grab the date field, it's in UTC and not in the user's locale. I understand why, because Drupal stores dates as UTC in the database. (Note: node.field_event_start_date.value is equal to dateStartField as I just do some simple formatting with twig)

{{ node.field_event_start_date.value }}

I've found some suggestions such as the use of Intl extension of Twig which would give a Twig filter, localizeddate or format_datetime (I think localizeddate is the old version), but when I used composer to install the twig extensions (https://twig.symfony.com/doc/3.x/filters/format_datetime.html):

composer require twig/intl-extra composer require twig/extra-bundle

it doesn't work. The filters aren't recognized by Twig. I've tried looking at information from here. I've seen others reference the notion of enabling Twig extensions for Symfony projects but I'm not sure where that would be on the backend of the Drupal site. See image attached for the filter error:

Code with format_datetime that is suppose to take into account the user's locale (On https://twig.symfony.com/doc/3.x/filters/format_datetime.html the default use of format_datetime is suppose to take into account the current locale):

<span>Calendar Start Date TimeZone Format: {{ calStartDate|format_datetime }}</span>

I'm almost at my wits end on trying to format my UTC dates into a localized date via Twig that I can feed into a calendar link exporter. I know I can format a date to a specific timezone with the basic Twig filters, but I can't check for what the user's locale is, thus making this approach void since the locale would be dynamic and not static.

Is there a better approach? Should I create a php hook that modifies the date fields for node--event.html.twig? Would this be appropriate? I don't think I'd need to create a module just for this simple issue but I'm not sure.

Let me know if you have any leads or solutions to any of my problems.

Thanks,
Tanner

Lasutriv

Strip HTML tags from Field Collections in Services Views

4 days 16 hours ago

I'm trying to strip the HTML tags from a JSON response I generated using Services Views, but I'm not having any luck so far. I have a content type with a Field Collections field in it that is outputting HTML tags no matter what I do. I've tried the following:

  • Check Strip HTML tags in the field settings in the view
  • Set customize field HTML to 'None'
  • Set Customize field and label wrapper HTML to 'None'
  • All combinations of the above
  • Making sure to turn of all 'Provide default field wrapper elements' options

Am I missing anything? My output still looks like this in my json:

"Animals": [ "<div class=\"entity entity-field-collection-item field-collection-item-field-product-animals clearfix\">\n <div class=\"content\">\n <div class=\"field field-name-field-product-animal field-type-taxonomy-term-reference field-label-above\"><div class=\"field-label\">Animal:&nbsp;</div><div class=\"field-items\"><div class=\"field-item even\">Big</div></div></div><div class=\"field field-name-field-product-withdrawal-time field-type-text field-label-above\"><div class=\"field-label\">Withdrawal time:&nbsp;</div><div class=\"field-items\"><div class=\"field-item even\">25 dg</div></div></div> </div>\n</div>\n", "<div class=\"entity entity-field-collection-item field-collection-item-field-product-animals clearfix\">\n <div class=\"content\">\n <div class=\"field field-name-field-product-animal field-type-taxonomy-term-reference field-label-above\"><div class=\"field-label\">Animal:&nbsp;</div><div class=\"field-items\"><div class=\"field-item even\">Rund vlees</div></div></div><div class=\"field field-name-field-product-withdrawal-time field-type-text field-label-above\"><div class=\"field-label\">Withdrawal time:&nbsp;</div><div class=\"field-items\"><div class=\"field-item even\">21 dg</div></div></div> </div>\n</div>\n", "<div class=\"entity entity-field-collection-item field-collection-item-field-product-animals clearfix\">\n <div class=\"content\">\n <div class=\"field field-name-field-product-animal field-type-taxonomy-term-reference field-label-above\"><div class=\"field-label\">Animal:&nbsp;</div><div class=\"field-items\"><div class=\"field-item even\">Pluimvee ei</div></div></div><div class=\"field field-name-field-product-withdrawal-time field-type-text field-label-above\"><div class=\"field-label\">Withdrawal time:&nbsp;</div><div class=\"field-items\"><div class=\"field-item even\">6 dg</div></div></div> </div>\n</div>\n"

Any help on this is greatly appreciated.

Sander van't Veer

How do I specify php.ini settings (or a complete file) for Drush?

4 days 17 hours ago

Before continuing, let me explain that I've tried the methods I've been able to find in documentation. Drush 12.5.2.0 is installed in the project by composer.

I've tried adding export DRUSH_INI='/Users/myusername/.drush/drush.ini' and export PHP_INI='/Users/myusername/.drush/php.ini' to my .zshrc file.

I've tried simply adding a drush.ini file to /Users/myusername/.drush and to /Sites/MAMP/foo/drush.

Drush is successfully finding drush.yml files in all the valid locations I've tried, but it seems to be ignoring every different attempt I've made to get it to find the php settings I want it to use. drush status continues to show the standard php.ini file is active, and when I try using a drush.ini file for overrides, the memory limit remains unchanged. It's working fine in every other respect.

What am I doing wrong here?

WRD

How do I add a Confirm Order button in Commerce Checkout?

4 days 18 hours ago

Using Commerce Kickstart 2

With the default checkout, the payment is taken on the Review page. Then the next page (Payment) processes with the merchant (in our case Authorize.Net).

Then there is a Confirmation Page... and the only pane on that page is Express Checkout Review and confirm' (does that refer to Paypal?).

I guess I'm expecting to a see a 'Confirm Your Order' button of some kind, but it never appears. Basically, the order is processed and goes immediately to 'Completed'.

How do I get that Confirmation page to appear?

Customers will expect to see a Confirm Order page -after- they have entered their payment... rather than going -immediately- to 'Completed'.

jchwebdev

Migration with custom files path

4 days 19 hours ago

I have to migrate a website from Drupal 7 to Drupal 9. My Drupal 7 files were located in this directory : sites/mywebsite/files In Drupal 9, files will be located in this directory : sites/default/files

While paths are automatically managed by media module in ckeditor in D9, the path for every file is still sites/mywebsite/files/myfile.pdf. I don't know where to change it.

How to fix this?

Thanks

Alexander

Avoid user to multiple purchase of same product

4 days 20 hours ago

I would like avoid a user to buy the same product twice or more, I'm not speaking about the quantity limitation during the checkout (I've already set quantity to 1 for every purchase)...for example..after a user has bought a product(He has completed the checkout process) I want that he can't buy again this product. Could you help me? Thank you in advance!

gio

Webform i18n doesn't work

4 days 21 hours ago

We have installed and enabled:

  • Webform 7.x-4.0-alpha6
  • Webform Localization 7.x-4.x-dev
  • Internationalization 7.x-1.7

We have created several webforms (in English).

When I look admin/config/regional/translate/translate and select "Limit search to" to "Webform Localization", I see an empty list of strings to be translated.

This way we are unable to translate our webforms. Please help.

porton

How do I retrieve a plugin block field's translated value?

4 days 22 hours ago

I created a module that installs a block with some fields when installed. I added a schema file, and altered the blockSubmit() function so that the translation is saved in the schema.

Here is my module.schema.yml:

block.settings.worldwide: type: block_settings label: 'Worldwide' mapping: overtitle: type: label label: 'Overtitle'

Here is the blockSubmit() function from my Block plugin:

public function blockSubmit($form, FormStateInterface $form_state) { parent::blockSubmit($form, $form_state); $values = $form_state->getValues(); $block_name = $this->getPluginId(); $this->blockConfigFactory->setBlockConfig($block_name, 'overtitle', $values['overtitle']); $this->setConfigurationValue('overtitle', $values['overtitle']); }

When saving, I have no error, and can translate the field, which will keep the translation when updated. So everything seems to work. Additionnally, the website displays correctly what I saved for the default language.

Now, let's say that the default language is english and the alternative is french. My issue is that if I set the website in french, the default (english) value will keep displaying.

However, I can't figure out a way to displayed the saved translation when I want to look at the block in a language that has the block's translation saved. I have no idea where to look, and can't seem to find relevant stuff on internet.

Thank you in advance

Jaeger

See all nodes where user profile entity reference matches the same entity reference on the node

4 days 23 hours ago

I have the Profile 2 module where a user selects a zip code (which is an entity reference to the content type ZipCode)

The ZipCode content type has an entity reference to a Region content type.

Finally, there is a content type called Schools which has an entity reference to the ZipCode content type.

I would like to display all schools that match the region of the logged in user. Logically this means finding the user's region, and then all schools with the same region, through the zip code...

I can't for the life of me figure out how to do this. Any help would be appreciated.

kylex

Bulk redirect update from CSV: in code or manually?

5 days 1 hour ago

I have a D7 question. My latest site change involves using the Path Redirect Import module and drush path-redirect-import to bulk-create a bunch of URL redirects from a CSV file. It works fine in dev on my Linux box and I need to deploy it to test on Pantheon.

I'm striving to do code-based deployments, so I use Features and a MYSITE.install module with hook_update_n() calls.

1) Is it a best practice or am I misguided in trying to code a hook_update_n() to perform the DB update? Code-based development aims for recording every developer-initiated site change in code, right? Or are there cases where you don't commit something to code?

2) If the answer is "yes, you should do this in code", then I see that the drush_path_redirect_import function simply processes command-line options and executes:

$result = path_redirect_import_read_file($file, $options);

so I should simply do the same in my hook_update_n(), right?

UTAN_dev
Checked
14 hours 21 minutes ago
most recent 30 from drupal.stackexchange.com
Subscribe to Drupal StackExchange feed