Drupal StackExchange

Show/hide fields in a form based on the value of a checkbox

2 days 11 hours ago

Is there a way to hide a specific or specifics fields in Drupal when you create content until you checked a checkbox?

Now it looks like this:

I need something like this:

But I need some checkboxes to decide if I have a certain field to show or not. Like this:

(Fieldcollection item 'some information' is showing up now because I checked the checkbox before the label)

Is there a module for this?

What would be nice is if all fields only become mandatory if you checked a checkbox.

honline

How to disable redirection to the node after node form submission

2 days 12 hours ago

I have a node form exposed in the front-end to allow visitors to add their organisation to the list of partners. Below the form, I have exposed view block with the list of existing partners.

When a visitor enters a new organisation to the list I want the form just to add a new node type "partner" and reload the page/block without redirecting to the node content (node/[node ID]).

At the beginning I ed taxonomy terms instead and it worked as it should, now I want to achieve the same with node entity.

I have tried various solutions but none of it works correctly and I didn't find much by googling it.

For example, this is not functioning:

function THEME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id) { if ($form_id == 'node_partners_form') { $form_state->disableRedirect(); // This is not functioning } }

This does not work either:

function THEME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface &$form_state, $form_id) { if ($form_id == 'node_partners_form') { foreach (array_keys($form['actions']) as $action) { if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') { $form['actions'][$action]['#submit'][] = 'THEME_node_form_submit'; } } } } function THEME_node_form_submit($form, &$form_state) { $form_state->setRedirect(Url::fromUri('internal:/node/1')->toString()); } => Error: Route /partners does not exist.

Value of attribute action in the exposed node form is correct and therefore I think the proper solution should be elsewhere then altering form properties - probably it has more with the Drupal behaviour after adding a new node.

<form action="/en/partners">...</form>
Boštjan Biber

How to Logout user with Basic auth?

2 days 13 hours ago

I can log in, perfectly fine, but can't get logout to give me a JSON response. Currently, I can only do POST to

d8.com/user/logout?csrf_token=123&?_format=json

and that would log out, even though the token 123 is not the same as the given csrf-token at login or the logout token. This doesn't work without the token query, even though cookie/session isn't enabled anywhere

("message": "'csrf_token' URL query argument is missing.").

The logout happens when hitting a 403 forbidden on that URL.

Other info: csrf_token=123 is the actual query, doesn't need to be csrf-token or the log out token is given at login Version: 8.5.3 The only basic_auth turned ON, at all endpoints.

Sakox

How to fallback to default language when listing nodes in a view if no translation is available

2 days 14 hours ago

I have a list of projects, mostly in english, but some are translated in French.

When i visit the French version of my website, how can I list all projects that are translated in French and if no translation is available for a specific node, display the english counterpart.

Is that something possible in the view UI ? Or I'm guessing with a hook_query_alter.

Thanks,

Ebpo

Replacement pattern for one value of a multivalue field in views

2 days 15 hours ago

Rewriting the results of a views field, I wonder if there is a way to use a replacement pattern for the first, second and third value of a multivalue field.

In my case, as example:

I have tried to use this rewritten tags field: [field_tagging:0] [field_tagging:1] [field_tagging:2]

However, this is not rewritten/recognized as replacement patterns.

The result I need, is that in the views field has three tag links, which have a rewritten path (in this case it also uses !1 for the contextual value in the URL)

Yuri

How to link different contents together and display the linked content on the same page?

2 days 16 hours ago

I am fairly new to Drupal and would need some help.

on my site I have to show a few images (A - B - C - D ) created by a content type X.

Each of these images will link to a different content Type Y ( 1 - 2 - 3 - 4 ).

So when I click on A , the content 1 should show below it. Same for content B -2 , C -3, D-4.

I am not sure how to achieve such a result and what are the tools to use.

Thank you for your help.

newbie

Best no-charge Drupal alternatives to Acquia's Site Studio [closed]

2 days 16 hours ago

This is a general one. I would like to know better the spectrum of choices for Acquia Site Studio alternative in 2024.

The most important features from my perspective are:

  • ability to create many reusable visual web components relatively quickly (doesn't have to be low-code though)
  • possibility to configure how the components look just via UI
  • easy for content editing from UI
  • working well with standard Drupal's architecture (no not-flexible black-box thing inside my CMS)
  • works well with Drupal 9+

Thanks for any insights that you may have!

Adamssef

Checkboxes not rendering

2 days 17 hours ago

All the other form elements render properly. Radios and Checkboxes do not. The title and descriptions show up, but not the boxes or radios.

$options7 = array(); foreach ($resqry1 as $option) { $options7[$option->id] = $option->id; } $form = array(); $form['lis'] = array( '#type' => 'checkboxes', '#options' => $options7, ); return $form;

Please help me out. Thanks

Jack15

Image style is not rendering

2 days 18 hours ago

My field_image is not rendering on user-profile.tpl. I have the following code (two different ways to render for testing):

$image = field_get_items('user', $user, 'field_image'); $output = field_view_value('user', $user, 'field_image', $image[0], array( 'type' => 'image', 'settings' => array( 'image_style' => 'header_image_160x160', ), )); print render($output);

This produces the following in html:

<img src="https://coinme.io/sites/default/files/styles/header_image_160x160/public?itok=f31sbmSd" width="160" height="160" alt="">

I get the dead image logo. It is missing the final part of the file structure. And this is how I normally render:

$to_render = field_view_field('user', $user, 'field_image', array('settings' => array('image_style' => 'header_image_160x160'))); print render($to_render);

This is showing the default image, even though the image does exist:

https://coinme.io/sites/default/files/styles/header_image_160x160/public/images/profile/profile-large.png?itok=rb-2qFOw

I have the same field in a content type which is rendering correctly (only difference being the $user user -> $node node.

<?php $to_render = field_view_field('node', $node, 'field_image', array('settings' => array('image_style' => 'header_image_160x160'))); print render($to_render);?>

So it appears that when using user-profile specifically is the issue. I have also tried adding a new field type and same effect. Any suggestions?

Thanks, Paul.

Paul