Drupal StackExchange

User authentication handled by a web service

2 days 13 hours 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 14 hours 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 15 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 16 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

Uploaded file not shown in custom content type / Image not attached to content type

2 days 17 hours ago

In Drupal 7, I am trying to upload an image that belongs to a custom type.

I click the Browse button, choose the file and upload. Until there, all seems to work well.

However, when I click next, instead of the add alt, title and text, I get only a screen that says Destination *, and with a Previous and Next buttons, as shown below. The save button is never displayed, and the image is not shown.

However, the image is there if I check the files through the admin, moreover, all goes well If I add the image through the file/add, it is just in the custom type that I get the error.

I am logged in as an administrator and I have all the permissions checked in Media and File Entity

My files folder permissions are 755, and the javascript console shows: 'Attr.nodeValue' is deprecated. Please use 'value' instead. in jquery.js

Resource interpreted as Script but transferred with MIME type text/html: "about:blank" in browser?render=media-popup&types[]=image&activePlugins=&enabledPlugins=&schemes[]=public&schemes[]=…:92 (anonymous function)

Thanks in advance for your help.

Update, this doesn't work with Image widget nor Media Browser widget. Same site works in PROD, I suppose it is something with the file system settings?

elneto

True/False exposed Views checkbox for Computed Field

2 days 18 hours ago

Imagine a user has ten fields of type "List(text)" which each have for their widget "Check boxes/radio buttons". Each one is displayed to the user as a single value checkbox which asks the user to state whether they agree with something or not.

A distinct Computed Field of data type TinyInt uses custom PHP to examine the values of these List(text) fields checkboxes. If all are checked the Computed Field is set to have the value of 1. If any or all are unchecked the Computed Field is set to have the value of 0.

(Ideally I would like the Computed Field to be of Boolean type - so simple TRUE/FALSE - but this does not seem possible out of the box. Anyway, the real question is the following.)

In a View with exposed fields, how can you use the Computed Field as an exposed field that offers the user a single checkbox: "Find all users where the Computed Field value is 1: [•]".

If this isn't directly possible, I'm happy to have a workaround that involves creating a distinct (hidden) field in the user profile and then uses this for the Views exposed filter search. But I can't think of a way to do this right now... Thanks.

penname

Are hooks cached?

2 days 20 hours ago

I am trying to alter a views result after it's executed, and before it's rendered. I was originally using hook_views_pre_render(viewExecutable $view), but that wasn't updating any of the view results for one reason or another, so I switched over to hook_views_post_execute(viewExecutable $view) which DOES update view results, however, both hooks only work immediately after a cache clear.

Is there a reason this was done? It seems pointless to have these hooks if they only fire based on cache clears or cache being updated.

I am using the hook to compare a field in a result row to an array, and if it doesn't match a value in the array, then it removes the views result so it doesn't show up in the view.

Like I said in the post, this works in the initial view visit immediately after a cache clear, but as soon as you refresh the page the view is no longer using the hook. I've disabled views caching in settings, but it still seems to be behaving this way.

I am also curious why my normal views display responds to the hooks, but my REST export display does not. Does it need different hooks?

The exact code I am using is below:

function tcrp_server_status_views_post_execute(\Drupal\views\ViewExecutable $view) { if ($view->id() == "server_list") { $steamid = \Drupal::request()->query->get('steamid'); if ($steamid == NULL || $steamid == '') { unset($view->result); } $u = \Drupal::entityQuery('user') ->condition('field_steam_id',$steamid); $result = $u->execute(); $user = \Drupal\user\Entity\user::load($result[1]); foreach ($view->result as $k => $v) { $display = false; foreach ($v->_entity->field_access_roles->referencedEntities() as $reference) { if (array_search($reference->id(),$user->getRoles())) { $display = true; } } if (!$display) { unset($view->result[$k]); } } } }
Ex0r

Drupal Planet