Drupal StackExchange

Importing 'body' into 'paragraphs'

3 days 22 hours ago

I need to migrate an ordinary D7 multi-value long text field 'body' into D8 paragraphs . As paragraphs seem to be a reference, the migration will probably be more complex than just direct field mapping. Moreover, my target paragraphs include multiple fields, not only the text body but a title as well. Any idea or link how to accomplish this task?

Tomáš Bažant

How to get group id from custom url

4 days ago

I have some more custom url with og group id like

  1. www.example.com/students/6593
  2. www.example.com/results/6953
  3. www.example.com/book-listing/5367/6953

    here 6953 is a group id.

these are the sample link. my questions is how to get the group id from url? And i can't use arg(). because i have more no of url and group id position also varied.

There is any robust solutions for this.

Leopathu

Translations string email not work

4 days 1 hour ago

in D8 (multilanguage site, with two languages) i wanna send email for registration, etc by user preference of language of user (People -> Edit people -> Language Settings)

I've enabled all modules for translations and translations are saved correctly (see the attachment).

I followed this guide: https://www.valuebound.com/resources/blog/how-to-send-mail-programmatically-drupal-8 but not work for me.

The language code passed for the email is correct but the email is always send in default language (in my case, english).

ClodClod91

How to add complete value programmatically with Smart Date module?

4 days 2 hours ago

Iam using module Smart Date on Drupal 9.

And required programmatically add value to node in field with recurring rule (like Repeats every 1 year on xxxx-xx-xx). Technically, for this action also creating record in Rule table... But I understand, how this do... It seems like the smartdate module itself should make an entry in this additional table.

I used like this operation:

// Create new node: $node = \Drupal::entityTypeManager()->getStorage('node')->create([ 'type' => 'event', 'title' => 'My new note title', ]); // Assign value to field_date: $node->set('field_date', '2022-03-01'); // ...needed add here also rule of yearly recurring...

field_data - its name of smartdate field, but how add field value with complete data (repeats every, until and etc.)? Like in field widget on node edit with admin panel, there are more options available for this field.

Any ideas?

Eduard F.

Print image with alt text

4 days 3 hours ago

In the node template, I print an image gallery. I need to add the alt text.

<div class="field--name-field_gallery"> {{ content.field_gallery }} {{ content.field_gallery.alt_field }} </div>

There are many images, which are printed, but the alt text is not printed.

How can I print it?

Evi

Creating multiple destinations from one source

4 days 4 hours ago

I'm writing a Drupal 8 migration from a non-Drupal site where I need to migrate news articles that have inline images in them, sometimes more than 10. I've figured I'll do this in two steps:

  1. A migration for creating file entities for each image present in the source node body.
  2. A migration that creates news article entities, and for each image encountered, look up the file entity that was created in the 1st migration and use the File Usage API to indicate the file is used in this node.

My problem is the first migration. The Migration API wants to map a single source to a single destination. I need to be able to map a single source to MULTIPLE destinations, since I will be creating as many as 10 file entities from this single source row.

Does anyone know if this is possible, and if so, are there any examples in core or contrib migrating like this?

If I can't find a way to do it this way, I'll instead just migrate everything in the same single migration, and create the file entities on the fly. I'll just have to write a custom rollback implementation to remove them as well.

Brian

Drupal::request()->request->all() returns an empty array

4 days 5 hours ago

I have a custom controller that expects POST data. I had it working fine in 8.1.0 retrieving the data using \Drupal::request()->request->all() and \Drupal::request()->request->get($myvar).

Now, without any changes in my custom module, \Drupal::request()->request->all() is returning an empty array, and \Drupal::request()->request->get($myvar) is returning NULL.

Between the time it was working and when the issue arose, my hosting service Pantheon updated their Drupal 8 version from 8.1.0 to 8.1.1 and then 8.1.2. I suspect something may have changed then that affected this.

How can I fix this?

EDIT: Thanks for the comments, still not quite working...

Route YAML:

mymodule.foobar: path: '/foobar' options: _auth: [ 'basic_auth' ] defaults: _controller: '\Drupal\mymodule\Controller\FooBarController::foobar' _title: 'foobar' requirements: _user_is_logged_in: 'TRUE' _permission: 'administer site configuration'

Controller:

<?php namespace Drupal\mymodule\Controller; use Drupal\Core\Controller\ControllerBase; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; /** * Class FooBarController. * * @package Drupal\mymodule\Controller */ class FooBarController extends ControllerBase { /** * Provides content for the /mymodule/foobar path. * * @param \Symfony\Component\HttpFoundation\Request $request * The current request */ public function foobar(Request $request) { $content = $request->getContent(); $data = array(); $data['a'] = $request->get('foo'); $data['b'] = $request->request->get('foo'); $data['c'] = \Drupal::requestStack()->getCurrentRequest()->request->get('foo'); $data['e'] = $request->request->all(); $data['f'] = $content; $request = \Drupal::requestStack()->getCurrentRequest(); $content = $request->getContent(); $data['g'] = $request->get('foo'); $data['h'] = $request->request->get('foo'); $data['j'] = $request->request->all(); $data['k'] = $content; return new JsonResponse((object) $data); } }

Postman Request:

Note: This was working before with this exact code, correctly using basic HTTP authentication. There have been no changes other than these variations to my controller, and core updates.

Any more ideas?

baisong

Workbench Delete or Unpublish Multiple Nodes

4 days 7 hours ago

I have recently installed work bench, when we view all contents there is no option to select multiple nodes and apply delete or unpublish action on them. I need to edit each node and then delete each node separately. Please suggest any solution.

Fahad Ur Rehman