How can I replace the date picker with a text field that shows a date picker when it has the focus?

4 days 11 hours ago

I installed the Date Picker module, which works fine. This is what appears when I add the datepicker element to the form.

This is the code I use to add the datepicker element.

$form['date'] = array( '#title' => t('Select your birthdate'), '#type' => 'datepicker', '#date_format' => 'd/m/Y', '#date_year_range' => '-100:+0', '#default_value' => date("Y-m-d H:i:s", time()), );

I want to display a text field; when it has the focus, the calendar should be shown.

How should I change the code to make it possible?

user46175

500 error without any error log entry

4 days 12 hours ago

Migrated a Drupal 8 site to another server running apache2 PHP 5.5.9 (should be supported). Apache returns 500 when index.php requested, but no errors are logged anywhere. I tested by forcing an intentional PHP error in index.php and the log contains PHP errors.

I also excluded database connection problems. Taking settings.php out redirects me correctly to /core/install.php and no error is thrown.

BrrBr

How to inject code into node body after x paragraph

4 days 13 hours ago

Trying to figure out if there is a way to inject code after the first or second paragraph on a node.

More specifically I am trying to inject an Adsense ad.

So far I haven't been able to find a solution or module that will do this.

Can anyone help?

I am not using paragraphs module. Just looking how to inject code right after the third or fourth

tags on the body of the node.

Progonat

How do I print an exposed filter block in a template file?

4 days 14 hours ago

I have a view with an exposed taxonomy filter. I configured it to be displayed as a separate block so that I can print it another twig template. I tried this.

/** * Implements hook_preprocess_block() for block.html.twig. */ function themename_preprocess_block(array &$variables) { $variables['featured'] = views_embed_view('view_name', 'contextual_filter_block_machine_name'); }

Then I used {{ featured }} in the block template, but it doesn't work.

Is there another way to do this?

Binny

How to redirect into a specific page variant

4 days 15 hours ago

I installed panels, page manager, ctools and page manager redirect.

I made a (panel) page say foo1 - admin/structure/pages/add with variant type Panel. In this I put 5 variants named foo1variant1, foo1variant2, foo1variant3, foo1variant4, foo1variant5,

I also setup a page manager redirect say foo2: - admin/structure/pages/add with variant type redirect. In the end I should give the url it should go to foo1 en into foo1variant3, .

How to do this?

Justme

entity:file:undefined" plugin does not exist upload using curl to jsonapi

4 days 16 hours ago

I'm using php_curl to POST a binary image to my local D8.8 app but it keeps returning a 500 error:

The "entity:file:undefined" plugin does not exist. Valid plugin IDs for Drupal\Core\TypedData\TypedDataManager are: helpful list of D8 entities.

Using the example "Flow 1" from this doc page, I started out with this:

$binary = file_get_contents('Wilson.jpeg'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'http://localhost/jsonapi/node/doctor/field_photo'); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, "admin:mypwd"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $binary); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/octet-stream', 'Accept: application/vnd.api+json', 'Content-Disposition: file; filename="Wilson.jpeg"', )); curl_setopt($ch, CURLOPT_POSTFIELDS, $binary); $result = curl_exec($ch);

Searching I read that D8 is more strict about entity bundles, I can report that my field_photo for the doctor content type is instantiated as an image. Examining my app's /admin/structure/file-types/manage/image/edit I can see in the Known Mime Types section that application/octet-stream and image/jpeg exists and standing by. Rereading the error Drupal seems to perceive that this is a file but isn't clear what kind it is. I thought I was being clever and changed the Content Disposition from 'file' to 'image' but no such luck. Exact same error returned. Swapping it out to one of the suggested to 'entity:file:image' did not change the error message. It suggests to me that I need to do something in this curl header to prompt Drupal to understand that this is a file that has a plugin established for it.

Digging into the stacktrace I see that it's generating "entity:file:undefined" because the Bundle property for this entity is "undefined". Working backwards, in context of the doctor node definition, the field passes through the MimeTypeGuesser class has figured out that it is a jpeg and its attributes. But this gets lost when passed to the TemporaryJsonapiFileFieldUploader where it attempts to validate the File.

I've attempted adding "application/octet-stream" as a second entry underneath the "image/*" on the /admin/structure/file-types/manage/image/edit page but nothing changes. How should I associate its bundle to "image" so that I end up with "entity:file:image" and I can move on?

One thing that bothers me is that file uploading was added to the 8x-2.x branch and I'm reading that it is part of core. I'm on 8.8.5 and am assuming I have the latest after running composer update. I've checked some of the file diffs on jttps://git.drupalcode.org/project/jsonapi/ and it appears the files I'm working on are current, but it bothers me that I haven't resolved this. The json output from this module returns "jsonapi":{"version":"1.0" which is an indicator of the external jsonapi specification, not the drupal module.

sam452

Display summary + read more links if body content is long, otherwise display body alone

4 days 17 hours ago

We have a content type which has a customized template. In general, the body content of these nodes is short -- one to two sentences at most.

In some cases, however, the body content is a paragraph or more.

If the body content is shorter than 200 words, we would like to display the body field as-is.

If the body content is longer than 200 words, we would like to display the summary with a customized "read more" link.

Besides digging into the content array and counting words in the template, is there a graceful way to do this with view modes or field templates?

At the moment our clunky solution is to render both display types and swap between them with javascript, but this displays the "read more" link even when the body content is short enough to be displayed without the need for a summary.

node--custom.tpl.php <?php // Other fields above.. $summary = field_view_field('node', $node, 'body', [ 'label' => 'hidden', 'type' => 'text_summary_or_trimmed', ]); // Render summary of body, which is visible by default print render($summary); // Render full body as hidden with 'element-invisible' class (see field--body--timeline.tpl.php) print render($content['body']); ?> field--body--custom.php <?php if($element['#view_mode'] !== 'full'): // Display trimmed version ?> <div class="<?= $classes; ?>"> <!-- this is the summary field --> <?php foreach($items as $delta => $item): print render($item); endforeach; ?> <a class="fullTextButtonOn">Read More&hellip;</a> </div> <?php else: // Display full body text with the element-invisible class and hidden by default ?> <div class="element-invisible <?= $classes; ?>"> <!-- this is the full body field --> <?php foreach($items as $delta => $item): print render($item); endforeach; ?> <a class="fullTextButtonOff">&hellip;Read Less</a> </div> <?php endif; ?> Resulting HTML on render <div class="field field-name-body field-type-text-with-summary field-label-hidden"> <!-- this is the summary field --> <p>Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.</p> <a class="fullTextButtonOn">Read More…</a> </div> <div class="element-invisible field field-name-body field-type-text-with-summary field-label-hidden"> <!-- this is the full body field --> <p>Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.</p> <p>Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.</p> <a class="fullTextButtonOff">…Read Less</a> </div>
PHP84

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

4 days 18 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 19 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 20 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 22 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 23 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?

5 days 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

5 days 2 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

5 days 3 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?

5 days 4 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?

5 days 5 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
Checked
1 hour 20 minutes ago
most recent 30 from drupal.stackexchange.com
Subscribe to Drupal StackExchange feed