Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

4
votes
1answer
5k views

Custom entity operation links

I've built a couple of custom entities in Drupal 8 Vendor, defined as such: /** * Defines the vendor entity. * * @EntityType( * id = "vendor", * label = @Translation("Vendor"), * module ...
3
votes
3answers
2k views

Specific field tag based naming conventions (overriding views-view-field.html.twig for specific fields)

I've scoured the documentation and I simply cannot find an answer to this question regarding naming convention for twig files given a tagged view with the override of a specific field. Let me create a ...
3
votes
3answers
4k views

How can I redirect node page for a content type to custom URL?

I need to redirect all the pages for a content type to a custom URL in Drupal 8. I used to do this in Drupal 7 by implementing hook_init() with the function drupal_goto() or by using the Rules module....
2
votes
1answer
3k views

Programmatically get the list of fields of a custom content

I want to programmatically create a custom content (custom content created via the admin UI). Before the creation, I want to check the types of fields of my custom content. My custom content contains ...
1
vote
1answer
3k views

Custom autocomplete field

I am trying to create an autocomplete field for users. The following code is fine for username searches but the requirement is for a search by any part of the user's first and last name. $form['user'...
15
votes
2answers
25k views

How do I change the base URL?

In Drupal 7, we can quickly change the base URL of the website. How can I do this, in Drupal 8?
8
votes
1answer
4k views

How to programmatically render a contact form in a theme in D8

How to get the side-wide contact form (feedback) individually displayed in a custom block or other page then /contact (e.g. frontpage)? I've tried this code, but it is not working (are contact forms ...
7
votes
4answers
5k views

How to autoload classes from a 3rd party PHP library

I would like to use a 3rd party PHP library in my module and I wanted to ask what I need to do to autoload the classes? Example: Drupal\my_module\MyClass wants to instantiate ThirdPartyNamespace\...
7
votes
1answer
10k views

Get the public path directory

I want to save file programmatically in public path, and I want to know how can I get Public Directory path in Drupal 8. In Drupal 7, I would use the following code. drupal_realpath(...
6
votes
2answers
1k views

Cannot update: “No available releases found”

I cannot update some of the modules and the Drupal core itself from "Available Updates" menu. The error is "No available releases found". However, I can list the updates with drush ups. Why?
5
votes
1answer
4k views

How to prevent a block from being cached?

After login. I'm adding one sidebar block. Once I clear cache then only updates variable or it's value. namespace Drupal\test_demo\Plugin\Block; use Drupal\Core\Block\BlockBase; /** * Provides '...
5
votes
4answers
3k views

Entity Reference: Filter by an entity reference view not working as expected

I am attempting to get a taxonomy reference field select widget that shows a list of taxonomy terms, including some extra data from their fields. I have attempted to use the "Reference method" = "...
5
votes
2answers
3k views

Turn off Twig cache

I did Disable Drupal 8 caching during development step by step ( also finally rebuild the cache) but yet my changes in twig files not take effects without rebuild the cache. sites/default/services....
5
votes
4answers
1k views

How can I add Taxonomy Term to a Node's Breadcrumb?

The Node has attached a single Term. Current breadcrumbs rendered [HOME] >> [NODE_TITLE] Want to render like this. [HOME] >> [TERM] >> [NODE_TITLE]
5
votes
1answer
2k views

Cache controller with json response

I want cached a controller that returns a json.. I try this: $build = array( '#cache' => array( 'contexts' => ['ip'], ), ); return (new CacheableJsonResponse(['test'], 200))->...
3
votes
2answers
6k views

How to create views tabs in D8?

I can't get views tabs to work in D8, following the exact UI procedure that does work in D7. To be more precise, in D8 at /mypage I see no tabs at all, and at /mypage/tab2 and /mypage/tab3 I do see ...
2
votes
2answers
1k views

How to run Drupal console command from code?

I have found a lot of documentation on how to run Drush commands from code, but I'm specifically looking on how to run a Drupal Console command from code. I have some experience in Symfony and I know ...
2
votes
2answers
4k views

how to get the original entity on hook_entity_presave?

i actually need it for the content_moderation_state entity function hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity) { if ($entity->getEntityTypeId() !== 'content_moderation_state' ...
13
votes
3answers
3k views

What are cloned sites in Drupal 8?

When trying to export my site configurations from one Drupal 8 site to other I keep getting the following error The staged configuration cannot be imported, because it originates from a different ...
11
votes
2answers
8k views

How do I save uploaded file permanently in file_manged table?

How do I save a uploaded file with status equal to 1 in the file_managed table, in Drupal 8? Whenever I upload a file, it is stored in the file_managed table with status value 0. I have used File::...
7
votes
1answer
2k views

Can you change the list builder class used by an entity?

There's an entity created by another module and I'd like to change some of the fields used on a listing page. Currently that page is using the entity's list builder class. Is there a way I can define ...
6
votes
2answers
2k views

Understanding about login via REST API

I was reading this article. I would like to know how logging in with the REST API in Drupal 8 works. By default, when users log in, Drupal will verify username and password. After the login, the ...
6
votes
5answers
5k views

How do I load a third party PHP library?

I have a third party php library which I would like to use in a module. How do I do that in Drupal 8? In drupal 7, I have done things like the following code, but libraries_get_path() doesn't exist in ...
5
votes
2answers
3k views

How can I programmatically change the view mode?

In Drupal 7 I did something like: function mymodule_views_pre_render(&$view) { //dpm($view); if ($view->name == 'services') { $view->style_plugin->row_plugin->options['...
5
votes
1answer
2k views

Embed a contact form [duplicate]

Is it possible to take a contact form and embed it into a page.html.twig or node.html.twig file? Or is the form only accessible via its contact/machine_name link?
5
votes
2answers
1k views

Updating core with Composer doesn't work

I am on D 8.3.0-rc2 and want to update to D 8.3.0 stable. Composer is my only option (requirement of address module). Composer core update doesn't bring me beyond 8.3-0-rc2, not even forcing it. ...
4
votes
2answers
8k views

How to customize the user login form?

I'm trying to customize user login form in /user/login page and I want to use a hook_form_alter function to add some awesome style and placeholder to each of user login form fields and remove or hide: ...
4
votes
5answers
1k views

Block error on CMI

I have two identical sites on Drupal 8 (A and B), on (A) I created a custom block(block/add), and then I export the configuration(drush config-export) and import this config on (B) (drush config-...
4
votes
3answers
4k views

How do I programmatically update or delete menu items?

I have seen the post on how to create menu items programmatically in Drupal 8, but how do I update or delete menu items in D8? Clarification: by programmatically I mean dynamically so yaml config ...
3
votes
3answers
883 views

How do I export my site structure?

Since Drupal 8 is days away from release, I've started experimenting with rebuilding my personal site on it. The one feature I am really looking forward to is configuration management in code. ...
3
votes
1answer
2k views

Rename “Read More”

I wanted to rename "Read more" in teaser (node--blog--teaser.html.twig) to something like "Continue" or anything else. How can I achieve this?
3
votes
1answer
1k views

Programatically render a node in a specific language

I want to render a node display programmatically for sending it to a search engine. It works ok but is ignoring the language and renders the field labels in the source language (which is English). I ...
2
votes
2answers
2k views

How to change text format of summary/trimmed field?

Is there a straightforward way to change the summary/trimmed text to "full html" in Drupal 8? There are workarounds such as creating separate body fields and using them as the summary but I am ...
2
votes
1answer
358 views

Override a template for only one route

I want override the region default template. I did that with a hook theme from my module. I want override the region custom template but only for the front page. How can I do that?
2
votes
1answer
3k views

Drupal 8 CKeditor behaves LTR in an RTL site

I've installed Drupal 8.0.2 in a standard installation process and in English. I later changed The site's default language to Hebrew (Which is an RTL language) and my content type is now setted to ...
2
votes
3answers
2k views

Custom form submit handler is called, but node is not saved

There are many questions about a custom form submit handler not being called, but in my case, the handler is being called; however, the entity is not being saved. Specifically, I have a custom submit ...
2
votes
4answers
7k views

Get node alias in template

I create a about-us with Basic Page content type, and with path alias aliased it to \about-us( nid = 2),Now in template file I want to get path alias <li><a href="{{ ??????? }}">{{ '...
2
votes
1answer
414 views

How can I implement a non-CRUD function in hook_service_resources()?

This question is similar to this question but I don't understand how the URLs are modified enough for the answer there to make sense to me. The module adds retrieve and index operations by default. ...
1
vote
2answers
755 views

/index.php/ appearing in generated clean URIs

I have a Drupal 8 site with clean URLs. Recently, URLs are similar to example.com/index.php/page-url-alias. The page still loads correctly, but I don't want the index.php part to be indexed. If I ...
1
vote
2answers
2k views

How to display a taxonomy term's immediate children on its page?

In Drupal 8, how can I display a taxonomy term's immediate children on its page? For example, I have a hierarchical taxonomy vocabulary like this (simplified): Animals --Fishes ----Blennies ------...
1
vote
1answer
422 views

How to get cache metadata from nested render array when returning response?

I have a controller action that renders a list nodes and returns them, and only them. It's invoked via AJAX and the JS code just takes the result and inserts it into the page somewhere. My problem is ...
0
votes
1answer
617 views

Generate unique form ID based on context

When you try to build the same form twice on a page, the submit handler of the first form gets executed. In order to overcome this issue you need to generate a unique form ID. How do you generate a ...
0
votes
1answer
1k views

Drupal 8 create a template override for a view block within a custom module

The Question: In Drupal 8: How do I add a template override for a view block and have that twig file reside in a custom module - not my theme? Further Information: I have already created a custom ...
0
votes
1answer
741 views

Use external class in drupal 8 module with file name and class name [closed]

I have created a module in drupal 8 . I need to use a class which is in external file . File name : drupal.php Class name : class newman{...} In drupal.php ( have many classes ): <?php ...
0
votes
1answer
278 views

Sporadic permissions issue

We are running a Drupal 8 site with 400 or so pages of content. We have a number of "resource pages" were views generate links to content by topic area. Here is an example of one of those pages. ...
0
votes
0answers
182 views

{{ directory }} in Twig template in base theme breaks subtheme

Given a base theme called parent that is a child of stable, and a sub-theme called child whose base theme is parent, a Twig template implemented in the parent theme renders the wrong value for {{ ...
-1
votes
1answer
1k views

AJAX select returns 'illegal choice detected'

Create a settings form for a module in Drupal 8 - when a user selects a View from a list, the drop down under it should populate with the displays in that view. While the form updates the option list ...
10
votes
4answers
4k views

How to delete a content type, programmatically?

I programmatically created a content type during a module installation (using field storage configuration). I want to delete that content type while uninstalling the module. Is there any way to do ...
8
votes
6answers
13k views

How to add a Login / Logout link in Main navigation menu?

How can I add a Login link to the "Main navigation" menu? When a user clicks on the link, it should take them to the /user/login page. Once they login, the link should change to say "Logout" instead ...
5
votes
2answers
1k views

How can I add cache context to custom menu link?

I have two routes that receive user as route parameter, and i need a menu link for every one in account menu. So I added in my *links.menu.yml client_account_links: deriver: \Drupal\my_module\...