Drupal StackExchange

Multiple pagers in one page

22 hours 33 minutes ago

I have a view with two separate displays that is used in one single page. Both the displays are using a pager. To get things working I set a unique id for each pager under pager options. This works and I can use each pager independently. The problem is that the separator used in the url to distinguish between the two pagers is encoded as %2C. So my question is if there is a way to avoid this and if possible even change the character used?

Cyclonecode

How to get current product id from custom block?

23 hours 27 minutes ago

I've problem to get current product id from custom block displayed on product page. Here my code :

class TestBlock extends BlockBase { public function build() { $product = \Drupal::routeMatch()->getParameter('node'); $productid = $product->product_id(); return array( '#markup' => $this->t('Product ID : ') . '<h2>' . $productid . '</h2>', ); } }

Do you have any idea to get the current ID from product ?

Thank you for your help.

Webman

Two displays with an exposed filter

1 day ago

I have a view using one exposed form in a block with a couple exposed filters. I would like the same result set to be used in two displays that have a slightly different format.

  1. One of my exposed filters is not being "remembered" from one display to the other, even though the other filter fields are.
  2. When I navigate from one display to the other, the problematic exposed filter (a single checkbox) gets rechecked if it was unchecked.
  3. It appears that the query is being re-run when I go from display to display. I don't really want that to happen since I am using the same result set. I figured the query only should get run when you hit the SUBMIT button, not change displays.

I have tried to use a number of the hook_views_xxx functions to set and reset my exposed_input array value for the filter field, but I can't seem to get anything to work. I have also tried using the $_SESSION variable for the field to fix it, but no luck.

If I can understand what is supposed to happen with Views, I can keep trying to solve this myself, but I am really stuck and into this about 10 hours.

Bill

Custom user_register_form for Auto Assign Role registration pages

1 day 1 hour ago

I'm using a function[a] to get custom templates to work for all pages, including role registration pages set by Auto Assign Role. By setting the role registration path to user/register/<rolename> I'm able to use page--user--register--rolename.tpl.php to make custom pages.

What I'm trying to do now is use a custom user_register_form for each role registration page. Using this function[b] I'm able to use user-register-form.tpl.php to customize the registration form. This affects the form for both role pages though. I tried using the Field Permissions module, but because an anonymous user will be using both forms it's of no use here.

I'm thinking I need to change what user-register-form template the page itself is looking for, but I can't figure out how to do that.

a.

function THEMENAME_preprocess_page(&$vars) { if (isset($vars['node'])) { $suggests = &$vars['theme_hook_suggestions']; $args = arg(); // Remove first argument of "node". unset($args[0]); $type = "page__type_{$vars['node']->type}"; $suggests = array_merge( $suggests, array($type), theme_get_suggestions($args, $type) ); } }

b.

function THEMENAME_theme() { $items = array(); $items['user_login'] = array( 'render element' => 'form', 'path' => drupal_get_path('theme', 'THEMENAME') . '/templates', 'template' => 'user-login', 'preprocess functions' => array( 'THEMENAME_preprocess_user_login' ), ); $items['user_register_form'] = array( 'render element' => 'form', 'path' => drupal_get_path('theme', 'THEMENAME') . '/templates', 'template' => 'user-register-form', 'preprocess functions' => array( 'THEMENAME_preprocess_user_register_form' ), ); $items['user_pass'] = array( 'render element' => 'form', 'path' => drupal_get_path('theme', 'THEMENAME') . '/templates', 'template' => 'user-pass', 'preprocess functions' => array( 'THEMENAME_preprocess_user_pass' ), ); return $items; }
delz

How to fix missing php extensions problems in custom Docker image?

1 day 3 hours ago

There are many excellent questions here about automating the initial setup process for Drupal but I haven't seen any pertaining specifically to Drupal containers in Docker.

Here's my setup. I've kept the images/builds as vanilla as possible; the only Dockerfile I have is for composer, inspired by the accepted answer to this question.

docker-compose.yml

version: '2' services: drupal: image: drupal ports: - 8888:80 mariadb: image: mariadb environment: MYSQL_DATABASE: drupal8 MYSQL_USER: drupal8 MYSQL_PASSWORD: drupal8 MYSQL_ROOT_PASSWORD: drupal8 restart: always depends_on: - drupal drush: image: drush/drush composer: image: composer build: composer_init depends_on: - drupal - drush

Dockerfile for composer:

FROM composer RUN composer -vvv create-project drupal-composer/drupal-project /var/www/html --stability dev --no-interaction RUN cd /var/www/html RUN drush si -y \ --db-url=mysql://root:drupal8@localhost/drupal8 \ --site-name=drupal8 \ --site-mail=drupal8@foo.com \ --account-mail=drupal8@foo.com \ --account-name=drupal8 \ --account-pass=drupal8 >> /dev/null 2>&1

I spun up the build process by issuing docker-compose up -d --build. Now when the process reached the composer part, it blew up with the following message:

Resolving dependencies through SAT Dependency resolution completed in 0.001 seconds Your requirements could not be resolved to an installable set of packages. Problem 1 - drupal/core 8.5.x-dev requires ext-gd * -> the requested PHP extension gd is missing from your system. - drupal/core 8.5.1 requires ext-gd * -> the requested PHP extension gd is missing from your system. - Installation request for drupal/core ~8.5.1 -> satisfiable by drupal/core[8.5.1, 8.5.x-dev]. To enable extensions, verify that they are enabled in your .ini files: - - /usr/local/etc/php/conf.d/date_timezone.ini - /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini - /usr/local/etc/php/conf.d/docker-php-ext-zip.ini - /usr/local/etc/php/conf.d/memory-limit.ini You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Based on other answers/suggestions here, I added a Dockerfile to my drupal section and added RUN apt-get install php7.0-gd to the Dockerfile, but this now blows up with E: Package 'php7.0-gd' has no installation candidate.

I've ensured that the PHP version for this Docker image is PHP 7.

php --ini gives me:

# php --ini Configuration File (php.ini) Path: /usr/local/etc/php Loaded Configuration File: (none) Scan for additional .ini files in: /usr/local/etc/php/conf.d Additional .ini files parsed: /usr/local/etc/php/conf.d/docker-php-ext-gd.ini, /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini, /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini, /usr/local/etc/php/conf.d/docker-php-ext-pdo_pgsql.ini, /usr/local/etc/php/conf.d/docker-php-ext-zip.ini, /usr/local/etc/php/conf.d/opcache-recommended.ini

How can I resolve this error now?

Craig

Uninstalling Commerce Authorize.net: How to Remove Content?

1 day 4 hours ago

I'm trying to uninstall the Commerce Authorize.net module. I've deleted the payment gateways I was using. When I try to uninstall the module using the web interface I get this error:

The following reasons prevent Commerce Authorize.net from being uninstalled:

  • There is data for the bundle eCheck on the entity type Payment method. Please remove all content before uninstalling the module.
  • There is data for the bundle Authorize.net (Accept.js) on the entity type Payment. Please remove all content before uninstalling the module.

How can I remove this content? I hope it doesn't mean that I have to delete old orders that used those payment methods.

Scott Hollenbeck

Stemmer processor not working

1 day 4 hours ago

I have configured Search api module in my Drupal 8 search. This is the first time I am configuring search api. I am using database search and not solr. My problem is stemmer processor is not working properly. I am not getting intended result for keywords due to stemmer processor issue. Stemmer processor is not stemming the words while indexing but is stemming while search query is executed. For example the word 'cars' is stored in the database as 'cars' itself while indexing but when a search query for 'cars' is executed it stem the word to 'car' and I am not getting the result. How can I fix this.

Nabil

programmatically get child nodes referencing parent by entity reference uuid, using loadByProperties & entityTypeManager or other way without views

1 day 5 hours ago

I tried this answer:

https://drupal.stackexchange.com/a/298084/1082

But I can't seem to use

'field_scientists' => $entity_reference_uuid

where, in my case, field_scientists is a field of type Entity Reference UUID - which is a field type provided by https://www.drupal.org/project/entity_reference_uuid module

What happens for me is that I get nothing back, my results array from that example is empty.

Looking to do this programmatically in my own custom module, rather than use a Drupal View.

If there's another way e.g. that uses the ->query method for querying the database I'd be happy to use that programmatic approach.

Thank you.

Update

An example of a uuid of a node in my case is BMSSYS0000051988.

This was set in a migration import from a field in a CSV.

My attempts are:

1. based on the example in the other question: https://drupal.stackexchange.com/a/298084/1082

$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadByProperties([ 'type' => 'bol', 'field_parent_uuid' => $taxonkey, ]);

2. db query

$query = \Drupal::entityQuery('node') ->condition('status', NODE_PUBLISHED) ->condition('type', 'bol'); $and = $query->andConditionGroup(); $and->condition('field_parent_uuid', $taxonkey); $query->condition($and); $result = $query->execute();

where $taxonkey is BMSSYS0000051988

both 1 and 2 attempts above return an empty array.

Update 2

here is my migration config that shows uuid being written to from a field in the csv. Is this legal? Should a developer's code change the uuid value or should uuid only be handled by Drupal core?

dependencies: { } id: bol_csv_import class: null field_plugin_method: null cck_plugin_method: null migration_tags: null migration_group: defaultl: publicbins label: 'Import bol species data' source: plugin: csv path: ./data/taxonomy_species_with_unpacked_bold.csv delimiter: ',' enclosure: '"' header_offset: 0 ids: - uuid fields: - name: uuidl: publicbins label: 'NBN id' - name: parent_uuid label: 'NBN id of parent' - name: name label: Name - name: rank label: 'Taxonomic Rank' - name: taxon_key label: 'Taxon Key' - name: authority label: authority - name: specimenrecords label: specimenrecords - name: publicrecords label: publicrecords - name: publicbins label: publicbins - name: taxid label: 'NBN Taxon ID' process: title: name uid: plugin: default_value default_value: 1 uuid: uuid field_parent_uuid: parent_uuid field_taxon_key: taxon_key field_authority: authority field_rank: rank field_num_bold_barcode_specimens: specimenrecords field_num_bold_public_records: publicrecords field_num_bold_public_bins: publicbins field_bold_taxon_id: taxid type: plugin: default_value default_value: bol destination: plugin: 'entity:node' migration_dependencies: null

Update 3

I'll write a db query to solve this issue. Running a command line sql indicates this approach could work:

MariaDB [db]> select * from node where nid = 246; +-----+------+------+------------------+----------+ | nid | vid | type | uuid | langcode | +-----+------+------+------------------+----------+ | 246 | 248 | bol | NBNORG0000041189 | en | +-----+------+------+------------------+----------+ 1 row in set (0.001 sec)
therobyouknow

Setting exposed filter default value from query string

1 day 6 hours ago

I have a view which show products and an exposed filter block (category, manufacturer, price).

I want to set category default value from URL, like this:

/browse-products/category-id

though, I wrote this module which take the parameter from URL and put it into exposed filter default value.

function mymodule_form_alter(&$form, &$form_state, $form_id) { global $request; if ($form_id == 'views_exposed_form') { $category_id = (int)($request->attributes->get('_raw_variables')->get('arg_0')); $form['category_id']['#default_value'][$category_id] = $category_id; dpm($form['category_id']); } }

dpm output for /browse-products/5

Array ( [#type] => checkboxes [#multiple] => 1 [#options] => Array ( [5] => Tablets [10] => -Ainovo [7] => -Galaxy Tab [6] => -IPad [1] => Smart Phones [4] => -Galaxy [3] => -IPhone [9] => --IPhone C [8] => --IPhone X ) [#size] => 9 [#default_value] => Array ( [5] => 5 ) [#bef_nested] => 1 [#theme] => bef_checkboxes )

but it doesn't work?

another thing, why dpm($form) prints the views exposed form data twice!

update 1: I tried something like this (but didn't work):

function mymodule_views_pre_build(Drupal\views\ViewExecutable $view) { $view_filters = $view->display_handler->getOption('filters'); $view_filters['field_category_target_id']['value'][8] = 8; $view->display_handler->setOption('filters', $view_filters); }

or this:

function mymodule_views_pre_build(Drupal\views\ViewExecutable $view) { $filters = $view->getExposedInput(); $filters['field_category_target_id'] = 8; $view->setExposedInput($filters); }
Wisamx

Limit row items to 1 as per the GROUP BY result in Views 3.x

1 day 7 hours ago

I'm trying to limit row items to 1 as per the GROUP BY result in Views 3.x, below is the view which I've created but I'm missing the key part from that, below is the exported code of my view.

$view = new view(); $view->name = 'position'; $view->description = ''; $view->tag = 'default'; $view->base_table = 'node'; $view->human_name = 'Position'; $view->core = 7; $view->api_version = '3.0'; $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ /* Display: Master */ $handler = $view->new_display('default', 'Master', 'default'); $handler->display->display_options['title'] = 'Position'; $handler->display->display_options['use_more_always'] = FALSE; $handler->display->display_options['access']['type'] = 'perm'; $handler->display->display_options['cache']['type'] = 'none'; $handler->display->display_options['query']['type'] = 'views_query'; $handler->display->display_options['exposed_form']['type'] = 'basic'; $handler->display->display_options['pager']['type'] = 'none'; $handler->display->display_options['pager']['options']['offset'] = '0'; $handler->display->display_options['style_plugin'] = 'table'; $handler->display->display_options['style_options']['grouping'] = array( 0 => array( 'field' => 'field_home_page_anchor_position', 'rendered' => 1, 'rendered_strip' => 0, ), ); $handler->display->display_options['style_options']['columns'] = array( 'title' => 'title', 'field_home_page_anchor_position' => 'field_home_page_anchor_position', ); $handler->display->display_options['style_options']['default'] = '-1'; $handler->display->display_options['style_options']['info'] = array( 'title' => array( 'sortable' => 0, 'default_sort_order' => 'asc', 'align' => '', 'separator' => '', 'empty_column' => 0, ), 'field_home_page_anchor_position' => array( 'sortable' => 0, 'default_sort_order' => 'asc', 'align' => '', 'separator' => '', 'empty_column' => 0, ), ); /* Field: Content: Title */ $handler->display->display_options['fields']['title']['id'] = 'title'; $handler->display->display_options['fields']['title']['table'] = 'node'; $handler->display->display_options['fields']['title']['field'] = 'title'; $handler->display->display_options['fields']['title']['label'] = ''; $handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE; $handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE; /* Field: Content: Home Page Anchor Position */ $handler->display->display_options['fields']['field_home_page_anchor_position']['id'] = 'field_home_page_anchor_position'; $handler->display->display_options['fields']['field_home_page_anchor_position']['table'] = 'field_data_field_home_page_anchor_position'; $handler->display->display_options['fields']['field_home_page_anchor_position']['field'] = 'field_home_page_anchor_position'; /* Sort criterion: Content: Post date */ $handler->display->display_options['sorts']['created']['id'] = 'created'; $handler->display->display_options['sorts']['created']['table'] = 'node'; $handler->display->display_options['sorts']['created']['field'] = 'created'; $handler->display->display_options['sorts']['created']['order'] = 'DESC'; /* Sort criterion: Content: Home Page Anchor Position (field_home_page_anchor_position) */ $handler->display->display_options['sorts']['field_home_page_anchor_position_value']['id'] = 'field_home_page_anchor_position_value'; $handler->display->display_options['sorts']['field_home_page_anchor_position_value']['table'] = 'field_data_field_home_page_anchor_position'; $handler->display->display_options['sorts']['field_home_page_anchor_position_value']['field'] = 'field_home_page_anchor_position_value'; /* Filter criterion: Content: Published */ $handler->display->display_options['filters']['status']['id'] = 'status'; $handler->display->display_options['filters']['status']['table'] = 'node'; $handler->display->display_options['filters']['status']['field'] = 'status'; $handler->display->display_options['filters']['status']['value'] = 1; $handler->display->display_options['filters']['status']['group'] = 1; $handler->display->display_options['filters']['status']['expose']['operator'] = FALSE; /* Filter criterion: Content: Type */ $handler->display->display_options['filters']['type']['id'] = 'type'; $handler->display->display_options['filters']['type']['table'] = 'node'; $handler->display->display_options['filters']['type']['field'] = 'type'; $handler->display->display_options['filters']['type']['value'] = array( 'news_story' => 'news_story', ); /* Filter criterion: Content: Home Page Anchor Position (field_home_page_anchor_position) */ $handler->display->display_options['filters']['field_home_page_anchor_position_value']['id'] = 'field_home_page_anchor_position_value'; $handler->display->display_options['filters']['field_home_page_anchor_position_value']['table'] = 'field_data_field_home_page_anchor_position'; $handler->display->display_options['filters']['field_home_page_anchor_position_value']['field'] = 'field_home_page_anchor_position_value'; $handler->display->display_options['filters']['field_home_page_anchor_position_value']['operator'] = 'not empty'; $handler->display->display_options['filters']['field_home_page_anchor_position_value']['value'] = array( 'min' => '', 'max' => '', 'value' => '', ); /* Display: Block */ $handler = $view->new_display('block', 'Block', 'block'); $translatables['position'] = array( t('Master'), t('Position'), t('more'), t('Apply'), t('Reset'), t('Sort by'), t('Asc'), t('Desc'), t('Home Page Anchor Position'), t('Block'), );

SQL query generated by View is:

SELECT node.title AS node_title, node.nid AS nid, node.created AS node_created, field_data_field_home_page_anchor_position.field_home_page_anchor_position_value AS field_data_field_home_page_anchor_position_field_home_page_a, 'node' AS field_data_field_home_page_anchor_position_node_entity_type FROM {node} node LEFT JOIN {field_data_field_home_page_anchor_position} field_data_field_home_page_anchor_position ON node.nid = field_data_field_home_page_anchor_position.entity_id AND (field_data_field_home_page_anchor_position.entity_type = 'node' AND field_data_field_home_page_anchor_position.deleted = '0') WHERE (( (node.status = '1') AND (node.type IN ('news_story')) AND (field_data_field_home_page_anchor_position.field_home_page_anchor_position_value IS NOT NULL ) )) ORDER BY node_created DESC, field_data_field_home_page_anchor_position_field_home_page_a ASC
Rishi Kulshreshtha