Drupal StackExchange

Domain Access: Edit admin/domain/content/ display settings, filters etc

2 days 12 hours ago

I am using Drupal Commerce and Domain Access module and I wonder where I could be able to edit how page admin/domain/content is displayed. I would expect to find a View page which is utilised by this module to show content and to allow to add filters and fields.

I have got a multi-domain site with thousands of products and I need to filter content by manufacturer or other field and to assign all products with desirable keywoord to selected domains.

Am I missing anything? I have not found any corresponding View. Thank you for an answer

liam dupin

Add CSS classes to theme function

2 days 13 hours ago

I'm implementing hook_theme() in a custom module.

function monitor_chart_theme() { return array( 'chart_monitor' => array( 'template' => 'monitor_chart', 'variables' => array( 'container' => null, 'theme' => null, 'classes' => null, 'chart' => null, ), ), ); }

On the template file, I would like to add additional CSS classes the theme function gets in its parameters. I declared a preprocess function with the following code.

function monitor_chart_preprocess_chart_monitor(&$vars) { if ($vars['classes']) { foreach ($vars['classes'] as $class) { $vars['classes_array'][] = $class; } } }

The template file contains the following code.

<div id="<?php print $container; ?>" class="<?php print $classes; ?>"></div>

If I don't use the preprocess function, the class attribute of <div> contains just 'chart-monitor', the name of the theme function.

Is there a more elegant way to pass extra variables to a template file?

arrubiu

Twig cache files on load-balanced setup

2 days 15 hours ago

The Twig cache key (twig_cache_prefix) is based the modify timestamp of the Twig template file and a randomly generated key. This gives a problem with a load-balanced Drupal setup where every host has it own copy of the Drupal source files, with different timestamps for the same template files across the hosts.

In this setup each Drupal instance keep generating a new prefix for every other request (when the balancer is in round-robin mode).

Is there a workaround for this?

Lennert

A little question about Webform Views Integration

2 days 15 hours ago

Have set up the Webform module with Webform Views Integration. Created an additional view for webform submissions via cloning and alteration of 'Embed:Default', applied there a function from Views Aggregator Plus' armory to count the values in the fields. Then integrated that view into the submissions' table with considerable ease, gaining a dropdown that contains two views: default (Submissions) and custom (Quantity). How to switch them to get Quantity as default submissions' view?

Dre

Specify which Migrate entries need to be updated using prepareRow

2 days 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?

2 days 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

2 days 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

2 days 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

2 days 20 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