Questions tagged [8]

Version tags should be used only for questions that apply to a version only, not to merely say what version a site is using.

Filter by
Sorted by
Tagged with
4
votes
3answers
16k views

Get current language in template

In Drupal 7 the current language is a global variable we can access with global $language; $langcode = $language->language; I want to know how can we access the current language in a Twig file ...
2
votes
2answers
487 views

How do I add a custom textarea into the checkout screen?

I want to add 'Notes' textarea for adding addtional message by customer while placing the order. I have added additional textarea in 'Order types' page (/admin/commerce/config/order-types/default/...
5
votes
2answers
310 views

How to restrict a module to a specific core version?

Drupal 8.3 introduced some changes, which broke a custom module; fixing the changes causes the module to break in previous Drupal versions. One way to handle this would be to require Drupal core to ...
1
vote
1answer
965 views

Why I cannot get translated entities

I wrote service to get all necessary data for my page. Now I wanted to load them with translations. But whey I try, I got error: InvalidArgumentException: Invalid translation language (id of ...
0
votes
1answer
38 views

Let a user select the theme

For a few weeks, I have been developing a site based on Drupal 8 and so far, everything's working fine. Only recently I found a functionality that I had expected to be there, but that now seems to be ...
0
votes
1answer
1k views

How do I redirect to a route with POST method?

I want to redirect to a route and also want to send some parameters which I don't want to expose on URL. So, I need to redirect with a post method. How to do this? $form_state->setRedirect('route....
3
votes
1answer
2k views

Date field exposed filter - select year

Back in Drupal 7 I've created exposed filter with Year from date field. (Selet list). View all 2017 2016 2015 etc... And when creating such filter we had options like on this picture: BUT, now in ...
0
votes
0answers
13 views

Set two file_public_base_urls and two file_public_paths in settings.php

I need to set two file_public_base_urls and two file_public_paths in settings.php in Drupal 8.7. and have them associated with each other. For example: $settings['file_public_base_url1'] = 'http://...
0
votes
2answers
2k views

How do you perform a Guzzle POST request with “Basic Auth” for the current user?

In my class, I have the following request: $rest_response = $client->post($endpoint, [ 'auth' => ['admin', 'admin'], 'body' => $serialized_entity, 'headers' => [ ...
1
vote
1answer
570 views

Redirect to 404 page, if URL alias does not exist

I am developing multilingual site in Drupal 8. I added content in Turkish language and did not create any translation for that node. Suppose node ID is 123, so system URL is http://example.com/tr/...
0
votes
0answers
27 views

How to grant permission to FileSystem.php file

I navigate to admin/config/media/file-system in the drupal admin interface. I get this error Warning: mkdir(): Permission denied in Drupal\Core\File\FileSystem->mkdirCall() (line 244 of core/lib/...
1
vote
1answer
18 views

How to use hook_update_n to create a vocabulary

I want to create a standard vocabulary (no extra fields) in Drupal 8.7.5 programatically, using hook_update_N. I've never used this function before. So I'm a complete newbie. I've modified a simple ...
-1
votes
0answers
27 views

PHP fatal error when attempting to run drush [on hold]

When attempting to run drush, it gives no output. It just fails. Looking at the error logs how this fatal error: PHP Fatal error: Default value for parameters with a class type hint can only be ...
0
votes
0answers
21 views

How do I disable caching for the Forum module or, alternatively, how do I fix caching?

I use the normal standard Drupal Forum module with a clean Drupal 8 installation. After I have installed it, I have a problem where "2 new posts" shows for all users. In other words, the /forum page ...
1
vote
1answer
27 views

How to get my button in a dialog click?

I have added the following JS to a node form, it clones the submit button but clicking it inside the dialog (which does show up) doesn't submit the form in the browser, just nothing happens when the ...
-1
votes
0answers
23 views

How to bypass a required field in POST request?

I am creating a new article node using DRUPAL 8 Rest api through postman. I am able able to create new node using url /entity/node/?_format=json. My question is how can I by pass a mandatory field ...
0
votes
1answer
978 views

Edit CKEditor's config programmatically

I've created a Drupal 8 module that adds a custom plugin to the core's CKEditor. This plugin allows users to add tabbed content to their pages. The problem is that the plugin adds a class to the ...
0
votes
2answers
2k views

How to add image field to main navigation menu item

I am having a problem using MYTHEME.theme file to add image field in the menu item object. I need to be able to specify an image for each menu link/item! function HOOK_entity_base_field_info(...
0
votes
0answers
55 views

Is there something I'm missing in getting this to work correctly?

I followed this tutorial but am having some issues. I enabled menu_link_extras and layout_builder on my site. I enabled layout builder on my menu, added a menu link and added a block to that link's ...
-1
votes
0answers
28 views

How can I restore this functionality?

I recently just updated to 8.7 and for the most part everything is working well. In my dev environment I was working on a new feature using layout builder with menu_item_extras to apply a layout to ...
3
votes
0answers
47 views

What is the underlying logic for generating an icon map for a custom registered layout?

There seems to be a dearth of information on the internet about how to generate an icon_map for newly registered layouts in Layout Builder. I've gotten as far as finding a patch file from the project ...
0
votes
2answers
93 views

“Edit layout” form missing revision log message field

When I edit the layout for a given node it is missing a log message field in the revision area. Is anybody else seeing this or am I alone? In trying to diagnose: Where that particular revision log ...
3
votes
0answers
52 views

How do I achieve layout nesting?

We have a content type (Page) and a vocabulary (Sections). The content type has a reference field to the vocabulary, and the vocabulary has a reference to a menu. Also, we are interested in being able ...
3
votes
3answers
881 views

Routing match everything

i want to match in a route a 'random' URL with a random sub path, fox example: /example/1/a/b/c /example/c3/s ... i implement this route in my .routing.yml file modulo.validator: path: '/example/...
0
votes
2answers
35 views

How to remove a taxonomy vocabulary via database query

To manually remove a taxonomy vocabulary in the database, what tables/columns etcetera do I need to delete or modify? I have a "ghost" taxonomy - it shows up in the list, but doesn't exist anywhere ...
1
vote
1answer
33 views
+100

Custom Commerce Payment Gateway - Order Information Form

I have followed the documentation at https://docs.drupalcommerce.org/commerce2/developer-guide/payments/create-payment-gateway/getting-started#step-3-create-a-payment-gateway-plugin My ...
-2
votes
0answers
38 views

How to make a view that contains content that belongs to groups as well as doesn't? [on hold]

I have newsletters, some belong to no groups (they are universal) and some belong to groups . I want to be able to see both of them in the same view depending on whether a filter is applied or not ...
3
votes
1answer
4k views

Add a link field to block form

I've created a module with a custom block that extends BlockBase. To the block form I added multiple textfields and select boxes, by simply specifying the formatter in the '#type' configuration. My ...
0
votes
0answers
34 views

Can't Install search_api_solr and search_api [on hold]

I'm trying to install search-api-solr and search-api. I try first using composer and when I check composer.json they listed in the file. but drupal installation page not affected so I end to install ...
3
votes
1answer
901 views

Showing local tasks in toolbar with hook_toolbar: caching problem

I'm creating a module using the toolbar api showing all administrative functions in a more compact toolbar. I'm having "cache" troubles showing the local tasks in the toolbar... How can I keep these ...
5
votes
1answer
908 views

Get the submitted values from $form_state

Is there a function (in Drupal 8) to build an array containing the submitted values in $form state? If I use $form_state->getValues(), I get more values than the ones I need.
7
votes
2answers
8k views

Add link field in custom form

I want add link field (label + url internal/external) in custom form This not work: $form['test_ink'] = array( '#type' => 'link', '#title' => $this->t('Link title'), '#url' => '', )...
1
vote
2answers
918 views

Creating 2 forms to work together on the same page for the same query

I'm facing trouble coming up with the following approach: I will have 3 separate forms acting on the same query from third party API's. On the front page there is a shorter quick-form that would ...
62
votes
9answers
120k views

How do I access a field value for an entity (e.g. node) object?

node_load((int) $nid) loads a fully-populated node entity. $node->title->value gets the title, but how do I access field values in Drupal 8?
6
votes
3answers
281 views
+100

View display plugin “entity reference” not using translation

For some of my entity reference fields I'm using "Views: Filter by an entity reference views" as reference method. I've configured those views to use the current interface language for rendering (with ...
3
votes
3answers
1k views

How to duplicate nodes programmatically?

I want to create duplicate nodes of a content type programmatically. Is there any way to do this? Note: I don't want to use any module to do this.
0
votes
1answer
23 views

How to disable form button on ajax callback?

I have a button with ajax callback and I want to disable it on button click without page reload. Preferably inside ajax_function but it's not obligatory. $form['my_button'] = [ '#type' => '...
-2
votes
1answer
36 views

Calendar/datepicker popup not working on safari

Below is the date type form field I have in some form which renders on chrome correctly. $form['date']['air_date'] = array ( '#type' => 'date', '#title' => t('Air Date:'), '#required' =&...
0
votes
0answers
30 views

entity ref shows on node, but not when node is set as home page

I suspect I may just have a simple misunderstanding of how a home page is generated, but... In a Drupal 8.7.5 website, I have a node (basic page) that I've added a paragraph entity reference field to....
1
vote
1answer
348 views

How can I enable search on parts of a word and autocomplete suggestions?

I'm using Search API in Drupal 8. I tried with Search API pages and even views, but I didn't find %like% function query Can I do %like% in Search API or Views?
0
votes
0answers
25 views

Entity Reference View fails after update to drupal 8.7.6

Recently I updated my drupal site from 8.6.14 to 8.7.6. A previously-working Entity Reference View display that is connected to a form Autocomplete field stopped working. The spinning circle keeps ...
0
votes
0answers
24 views

Why is wrong ajax callback function called?

I have two buttons $form['button_1'] = [ '#type' => 'button', '#value' => false, '#ajax' => [ 'callback' => '::ajax_submit_1', 'wrapper' => 'wrapper_1', ], '#...
0
votes
0answers
31 views

How does will() actually test anything?

I'm beginning to learn about writing tests for Drupal 8 via PHPUnit and am unclear on how the will() method actually serves to test anything. Given this code (derived from examples and tutorials on ...
1
vote
1answer
18 views

Patch method sample code REST API

I am working on web services in drupal. I have created a sample module for get method to expose the data using web services. I have not found any sample code for the patch method. code for get method: ...
0
votes
0answers
18 views

Serialization of dependencies

I'm using Drupal 8.6 and I'm doing the serialization of a node. This node has related fields, which I also would like to serialize. In my case I have an article which has a photo gallery which has ...
-3
votes
1answer
30 views

How do I deploy a site?

I am following this link to set-up a Drupal 8 site, I am installing drupal-composer/drupal-project as a template for my composer install for the first time, as I forced myself into drupal 8 for future ...
0
votes
2answers
4k views

Display success message after submitting form

I am try to display an success message after submitting my form and redirect to next page. The code I am using is the following. public function submitForm(array &$form, FormStateInterface $...
2
votes
1answer
522 views

Can I have both Language and Country path prefixes?

On our site, paths are all prefixed by language and country. For example: http://example.com/en/us/about In Drupal 7, a previous vendor implemented this by using the Persistent URL module, which ...
-4
votes
0answers
29 views

Switch language without URL being switched

I want to switch language in my Drupal 8. My language detection is URL. But I don't want users to be able to override the language switch by typing in the address bar. For example www.mysite.com/ (...
1
vote
1answer
42 views

Cache pages/variables in hook_preprocess() for anonymous user

So I am having trouble understanding the caching of variables set in hook_preproccesses for anonymous users. It seems that the entire page is cached, and not rebuilt, even when set to no caching. With ...