Drupal StackExchange

Replacement pattern for one value of a multivalue field in views

1 day 19 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?

1 day 20 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]

1 day 21 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

1 day 21 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

1 day 23 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

User authentication handled by a web service

2 days ago

I seek your help and advice. By default, Drupal manages user authentification using the user module that resides in the "core/modules" and through the main Drupal Database. In my case, the user is authenticated through an external webservice, the process is as follow: 1- The user enters his credentials and click submit 2- the credentials are then sent to the webservice 3- the webservice checks the data(credentials) to the one he has in his database 4- upon validation the webservice sends a token (JWT) otherwise it sends 401 Unauthorized

PS: the admin will have normal login (through Drupal Database)

The question is how can I proceed to elaborate this process of authentification?

  • Is there some existing modules that could help with this?
  • should I override the existing user module or create a new module?

Any info will be of great help.

Abouhassane Abdelhamid

Message template with mail key

2 days 1 hour ago

In template_preprocess_mimemail_message() I checked that mail key is mimemail_message__subscriptions_mail__node-type-post, but none of these templates is using in the email:

mimemail_message__subscriptions_mail__node-type-post.tpl.php mimemail_message--subscriptions_mail--node-type-post.tpl.php mimemail-message--subscriptions-mail--node-type-post.tpl.php

What I'm doing wrong?

MelNik

Validation constraints on form fields ignored

2 days 2 hours ago

Trying to figure out custom validation with constraints, but no luck yet. Right now, my form posts content and gives no errors when form is filled out incorrectly.

(Please avoid suggesting validation modules -- I know those exist.)

Maybe somebody knows what I'm missing? Or maybe it's done different when I'm doing specific fields? Or maybe this isn't how to do it on a back-end content submission form? Here's what I have so far:

I built a module called "custom_validation." It contains custom_validation.module:

<?php /** * @file */ /** * Implements hook_entity_type_alter(). */ function custom_validation_entity_type_alter(array &$entity_types) { /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ $entity = $entity_types['node']; $entity->addConstraint('BlogpostError'); }

Then, in subfolder src/Plugin/Validation/Constraint, I've got two files. BlogpostErrorConstraint.php contains: namespace Drupal\custom_validation\Plugin\Validation\Constraint; use Symfony\Component\Validator\Constraint; /** * Prevent article creation if errors. * * @Constraint( * id = "BlogpostError", * label = @Translation("Added blog post category instead of story author in author field", context = "Validation"), * type = "string" * ) */ class BlogpostErrorConstraint extends Constraint { /** * {@inheritdoc} */ public $notByline = '%value is a blog post type. Please add a byline'; public $noImageSource = 'need image source'; }

BlogpostErrorConstraintValidator.php contains: namespace Drupal\custom_validation\Plugin\Validation\Constraint; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; /** * Validates the BlogpostError constraint. */ class BlogpostErrorConstraintValidator extends ConstraintValidator { /** * {@inheritdoc} */ public function validate($items, Constraint $constraint) { if (!isset($items)) { return; } // limit this to 'blog entries' content type if ($items->bundle() == 'blog_entry') { // now loop through each field... foreach ($items as $delta => $item) { // an array of phrases we don't want in the field $bad_bylines = []; array_push($bad_bylines,"Value one","value two","abc123"); // adding validation... //byline field if (in_array($item['field_byline'], $bad_bylines)) { // not sure of syntax here $this->context->addViolation($constraint->notByline, ['%value' => $item->value]); } //main image source field... if ($item['field_main_image_source'] == '') { $this->context->addViolation($constraint->noImageSource, ['%value' => $item->value]); } } } } }

turpentyne

How do I migrate translated content?

2 days 3 hours ago

I'm working on migration from an old Drupal 8 site to new Drupal 9 site:
I developed a source plugin to get data from D8 database:
My migration works, but it doesn’t migrate all my contents and get this error:

Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '8a7e1ba8-9b75-4813-80d6-99104c82efa5' for key 'node_field__uuid__value': INSERT INTO {node} ("vid", "type", "uuid", "langcode") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array

When I debug the issue and I have found that there is some translated nodes have the same nid vid only langcode is different like the example bellow.

I added the langcode as id in my source plugin but it doesn't help:

public function getIds() { return [ 'nid' => [ 'type' => 'integer', 'alias' => 'n', ], 'langcode' => [ 'type' => 'string', 'alias' => 'n', ], ]; }

How can i migrate those nodes ?
Used modules: Migrate/ Migrate plus / Migrate Tools .
Drupal Version : 9.0.3

berramou

Drupal Planet