Drupal StackExchange

Specify which Migrate entries need to be updated using prepareRow

1 day 16 hours ago

I have made a Migration that i run with Cron. My highwater field is the date changed, which is present in the XML (source) document. Then I do this in my cron function:

$result = $migration->prepareUpdate(); $result = $migration->processImport();

Problem is is this will update ALL nodes from the XML. I would like to only update those that have been changed, according to their modifiedAt date. If I just do:

$result = $migration->processImport();

Then nothing at all updates. I think processImport() would work if it were just about importing new items, but I also need to update any existing items that have changed. The ones that don't need updating can be skipped, of course. Is there another method I could call here? Is there a way I need to set up some kind of prepareRow to mark items as needing updating?

blablazo

How do I create an instance of an entity with all its fields attached?

1 day 17 hours ago

I am trying to create an instance of 'commerce_customer_profile' entity with all the extra fields of the customers address.

I am doing this inside a FeedsProcessor that will import users and their addresses from Magento.

I don't want to have to create a fake $form_state array and then use field_attach_submit() as it doesn't seem right to me.

The only other way I have found so far is:

$billing_profile = commerce_customer_profile_new('billing', $entity->uid); commerce_customer_profile_save($billing_profile); $full_billing_profile = commerce_customer_profile_load($billing_profile->profile_id);

$entity is the current user being created.

Which will then give me an empty instance of the new entity ready to populate and save but again it doesn't feel right.

Any help appreciated.

jbloomfield

How to pass Webform elements from controller to custom twig template

1 day 18 hours ago

I'm pretty new to Drupal and probably this is simple but I got stuck with this.

What I'm trying to do: I have created a custom module where I have defined a custom route to display my webfrom in custom twig template.

How and what to return from Controller so my webform elements will be available in custom twig template.

my_module.module /** * Implementation of hook_theme * * Since we have a lot to explain, we're going to use Twig to do it. */ function my_module_forms_theme($existing, $type, $theme, $path) { return [ 'my_template' => [ 'variables' => ['test_var' => NULL], 'render element' => 'form' ], ]; }

my_module/src/Controller/MyModuleController.php namespace Drupal\my_module\Controller;

use Drupal\Core\Controller\ControllerBase;

class MyModuleController extends ControllerBase {

public function content() { $my_form = \Drupal\webform\Entity\Webform::load('my_form_id'); $form = \Drupal::entityManager() ->getViewBuilder('webform') ->view($my_form);

$build = [ '#theme' => 'my_template', '#form' => $form, ]; return $build;

} }

In my twig template, I want to be able to use form elements like below. Please let me know how to achive this.

my-template.html.twig {{ form.element.name }} {{ form.element.email }}

Thanks

Alan

import address data from CSV

1 day 19 hours ago

I migrate my content from an old D7 site to D8 site. All went well, except the addresses from field address where not migrated to the new address field.

Then I use feeds, feeds_migrate, content-import... Nothing work for this.

Then finaly start learning how to do this in a custom module. I used the plugin from the module addres, I wrote my own plugin. No migration seems to work.

I have a CSV file with the addresses. There is also a NID row that is unique, I also try with the title field who also is unique. I try to import this csv file into my content type business. The nodes are existing with the NID numbers. Just try to fill the address in each content. All addresses are in Belgium.
Below my YML file in a custom module.

id: migzaal label: Adres veld migratie source: plugin: csv path: modules/custom/adresmigratie/assets/adresinvoer.csv header_row_count: 1 ids: - Nid process: nid: Nid field_adres: plugin: addressfield destination: plugin: 'entity:node' default_bundle: business overwrite_properties: - 'field_adres/address_line1' - 'field_adres/locality' - 'field_adres/postal_code' - 'field_adres/country'

Can someone guide me in the right direction. Thanks.

Belba

Drupal - add machine-name as css class to my blocks

1 day 19 hours ago

So I would like to give my blocks the internal machine name of the block as a CSS class? I can add the block ID and the block type as presprocess via theme.theme:

function xxx_theme_preprocess_block(&$variables) { // adding custom attribute class for block if ($variables['elements']['#base_plugin_id'] == 'block_content') { $blockType = strtr($variables['content']['#block_content']->bundle(), '_', '-'); $variables['attributes']['class'][] = 'block--type-' . $blockType; } }

but how exactly do I get the machine name of the block? Does anyone have a tip for me? Would I like to stick to programming and not install a module, or can I get the machine name more quickly via the Twigtemplate? Would be very grateful for any help.

Bavra

Bavramor

Filter date from current date to upcoming 7 days?

1 day 20 hours ago

I have a week type calendar view. It currently displays form SUN to SAT of the current week.

But I need to display it starting from current date to current date + 7 days

How can I achieve this?. I am using Calendar Module and created a view using it.

My view is displayed only if I add a contextual filter. With default value as current date. This adds a filter criteria from dates starting from the start of the week and end of the week.

user46121

composer install error

1 day 21 hours ago

I can't install anything because of this error:

[RuntimeException] Could not scan for classes inside "/app/vendor/symfony/serializer/src/" which does not appear to be a file nor a folder

and subsequently:

Could not scan for classes inside "/app/vendor/symfony/yaml/src/" which does not appear to be a file nor a folder

I navigated to that directory and the src folder is indeed missing...

I'm using Lando and switch the PHP to 7.1. I tried deleting the vendor directory and rerunning lando composer update and lando composer install but get the same errors.

AlxVallejo

Warning: Invalid argument supplied for foreach() in form_select_options() (line 2837 of includes/form.inc)

1 day 22 hours ago

I get the following erros on selecting the selectbox. Here onchang of this field will populate another checkbox with city details id zipcode using ajax callback.

$zipcode_options = get_all_zipcodes_ascending(); // Populate Ort on auktion clone. $selected = isset($auktion->zip_code) ? $auktion->zip_code : NULL; $selected = isset($form_state['values']['zip_code']) ? $form_state['values']['zip_code'] : $selected; $ort_options = _ajax_city_dropdown_options($selected); $form['zip_code'] = [ '#type' => 'select', '#title' => t('PLZ'), '#options' => $zipcode_options, '#default_value' => isset($auktion->zip_code) ? $auktion->zip_code : "", '#select2' => ['width' => '100%', 'placeholder' => t('Enter a zipcode'), 'allowClear' => TRUE], '#empty_option' => '', '#validated' => TRUE, '#required' => TRUE, '#ajax' => array( 'event' => 'change', 'callback' => 'ajax_example_dependent_dropdown_callback', 'wrapper' => 'dropdown-second-replace', ), ];

Referenced many links but cannot find a solution to resolve this issue.

References:

https://www.drupal.org/node/586576

populate drop down from results using ajax

http://techqa.info/drupal/question/203725/help-understand/solve-this-warning:-invalid-argument-supplied-for-foreach%28%29-in-views-that-requires-class-registry-clean-to-mend

developer

Drupal Planet

LN Webworks: How To Create Custom Token In Drupal: Step By Step Guide

1 day 20 hours ago

In Drupal 10, you can create custom tokens using your custom module. Before creating custom tokens, you need to have the Drupal tokens module installed on your Drupal site. This contributed module already comes with some predefined tokens. These defined tokens can be used globally.

Steps to Create the Drupal Custom Tokens

1. Begin by creating a yourmodule.module file in your custom module directory.

2. Establish your custom token type.

 

The Drop Times: Streamlining Local Development with DDEV, Docker, and NGROK

1 day 22 hours ago
Discover how DDEV, Docker, and NGROK can revolutionize your local development process. Our latest guide dives into the seamless integration of these powerful tools, offering you the most efficient way to set up, develop, and test your Drupal projects right from your local machine. Streamline your workflow and enhance productivity with our comprehensive insights!"