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
8
votes
3answers
7k views

How can I embed a View inside a content of a node?

How can I embed a view inside a content of a node in Drupal 8? I found something similar, for example in the question about "How do I embed a view inside a node?" or the Viewfield module, but it is ...
6
votes
3answers
2k 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?
6
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))->...
6
votes
4answers
6k views

How do I make a block that pulls the current node content?

Ok, so I know blocks in Drupal 8 have these things called "contexts" which allow Core to clear cache on a fine-grained basis. I can't find any decent explanation of how they work, or how to get page ...
5
votes
1answer
2k views

Use a twig template instead of a render array in a custom module admin page

I have a Drupal 8 custom module, and I want to display its configuration page using the admin theme. Usually, for this kind of pages I use, in the _controller property of my route, rather : a class ...
4
votes
1answer
8k views

Render image field from node in page.html.twig

I make my first steps with Drupal 8. I have a site with a header image. On a specific content type "Blog" I want to replace the standard header image with a node specific header image. So in the ...
4
votes
4answers
5k views

Switch a language programatically

Looking for a way to change between languages on our site, the Drupal 8s LanguageManager doesn't seem to have a straightforward method for this. We cannot use URL-switching, just want to do this ...
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
3k 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
2answers
5k 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' ...
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 ...
15
votes
2answers
28k 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
11k 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(...
8
votes
1answer
5k 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
3answers
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
3answers
17k views

Rendering an image field in page.html.twig with a custom image style

I'm trying to set up a slideshow that's unique to each page. The code for this needs to be in page.html.twig. I've got the slideshow mostly working, but I can only call the full image URL, not a ...
7
votes
2answers
10k 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: ...
7
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
1answer
4k views

Restrict content to a user role in a template file

I want to restrict a single node to anonymous users in Drupal 8. I don't want to use any module for it as its useless for single restriction as per me. I know that I can do it with something like ...
6
votes
1answer
7k 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
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
3answers
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....
4
votes
2answers
7k 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 ...
1
vote
2answers
383 views

Global preprocess for all links

Is there a some sort of global preprocessing hook for any link on a Drupal site? Use case: I've got an enquiry webform embedded on a node that presets some inputs by URL parameters. Editors can set ...
13
votes
2answers
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 ...
12
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 ...
12
votes
2answers
9k 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::...
8
votes
1answer
2k views

8 - How do i programmatically enable a user field under manage form display and manage display?

I've programmatically added a user field but i can't find a way to programmatically enable the field under 'manage form display' and 'manage display'. I tried exporting the 'entity view display' and '...
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
5answers
6k 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
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. ...
5
votes
4answers
5k views

Loading default image from a node field in page.html.twig

I want to print the default image of a node field into the page.html.twig template file in Drupal 8. On doing my research the easiest approach I could find was {% if node.field_image.entity %} <...
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
1answer
4k views

Set weight for JavaScript files loaded via theme.libraries.yml?

Im loading a JavaScript file via my theme's libraries.yml file. How can I change the weight of this file? I need the file to load before the core and module's JavaScript files. If I set header: true ...
4
votes
3answers
5k 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
4answers
8k 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="{{ ??????? }}">{{ '...
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 ...
3
votes
3answers
942 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. ...
2
votes
1answer
434 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. ...
2
votes
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 ------...
2
votes
1answer
4k views

How do handle exceptions?

I have a service provider that does stuff(for lack of a better word). Several functions in that service provider deal with a custom table in the database. Lets assume that in a function an id is ...
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
3answers
3k views

Alter the access of menu link before rendering

I need to alter the access of menu links before being rendered. In Drupal 7, we used hook_translated_menu_link_alter() for it. Drupal 8 change records show that there are no direct replacement for ...
2
votes
1answer
380 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
2answers
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 ...