Questions tagged [8]

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

Filter by
Sorted by
Tagged with
25
votes
8answers
38k views

Iterate through multiple value content field in Twig template

I need to take control over the rendering of a field_admin_tags field in a node.html.twig template. This WORKS: {{ content.field_admin_tags }} — Renders everything (label + all field values) {{ ...
19
votes
6answers
34k views

How to get each field value in views-views-unformatted--view-machine-name.html.twig?

I have an twig file: views-view-unformatted--view-machine-name.html.twig {# /** * @file * Default theme implementation to display a view of unformatted rows. * * Available variables: * - title: ...
13
votes
3answers
13k views

How can I setup multiple database connections?

Can anyone help me to setup connection with multiple databases connection in Drupal 8? I have database on the same server and I want to access it along with default Drupal 8 database.
26
votes
3answers
35k views

Programmatically update an entity reference field

I know I can update (or set a value for) an entity reference field in Drupal 7 with code similar to the following. $node['field_code_used_by'][LANGUAGE_NONE][0]['target_id'] = $id; I want to ...
25
votes
3answers
23k views

How do I render nodes, now that node_view() has been deprecated?

In Drupal 7 I frequently use node_view() for rendering nodes (using view modes) in blocks or pages as follows: $nids = array(123,456,789); $nodes = node_load_multiple($nids); foreach ($nodes as $node)...
12
votes
2answers
3k views

When should I create a service or a utility function?

I had this question in mind along all the last week: When I should create a service or an utility function? In the Drupal Core we have both Services and Utility functions, but I can't find the ...
10
votes
1answer
5k views

How do I get Views content items in “my language” but fall back to “default” if the content isn't translated?

This is probably very easy but endless searching has proved fruitless - there's lots of UI changes between the D7 and D8 versions of these modules it seems. What I want to do is create a blog in two ...
15
votes
2answers
8k views

What is the purpose of drush entity-updates?

After updating Drupal 8 modules, I have been warned on the Drupal 8 status page that: Entity/field definitions: The following changes were detected in the entity type and field definitions. ...
14
votes
3answers
17k views

How do I create menu links programmatically?

I need to add some links to existing menu (or to new) programmatically in Drupal 8.
10
votes
2answers
13k views

Programmatically get all names of an entity reference field

Example: I want to get all tag names that are inside field_tags of node 5. I can get the target_id with $node->field_tags->getValue(); But the problem is, I don't know what entity the target_id ...
10
votes
4answers
14k views

How to find image style URL from within twig template?

I'm implementing a node template that uses an image twice; once in a 'normal' way (i.e. using the image style defined in the field's display configuration for that view mode), and the other is as a ...
17
votes
3answers
47k views

Programmatically update a field's value

I want to update a node field's value when a node is updated. Tried using the code mentioned here Programmatically updating a node Drupal 8 use Drupal\node\Entity\Node; function ...
12
votes
4answers
6k views

Bootstrap from external script

I am trying to create Drupal entity instances from an external script that is not part of Drupal or a Drupal module. For Drupal 7 there was drupal_bootstrap to load the required Drupal dependencies. ...
6
votes
3answers
11k views

How do you print View fields on Twig?

I have a view and added the title as a field. For example: How do I print the title? In Drupal 7 it was as simple as views-view-fields--[viewname].tpl.php <?php print $fields["title"]-&...
5
votes
2answers
9k views

How to add Pager to a custom page?

I have a list of items which is fetched from an REST API and displayed in a page 10 at a time. These items are not stored in Drupal database in any way. I managed to have a basic pager which is just a ...
9
votes
1answer
4k views

Managing module library dependencies with composer

I've found Dependencies in a custom module with drupal-composer, How can I include a third party library in my custom module without using Composer Manager and How to manage contrib modules composer ...
7
votes
1answer
3k views

How can I override or disable a parent theme's CSS file?

I am trying to override the menu.css file in the default Classy theme through my library file. I have read through the documentation, but anything I tried doesn't work. What would be the correct ...
5
votes
4answers
11k views

How do I programmatically update the allowed values of a list field?

I have created a field field_time_zone in a content type = article. I want to set allowed values of list field, i.e. options of select list should be $zones = system_time_zones(); For this, I have ...
22
votes
4answers
16k views

Access user fields?

$account = \Drupal::currentUser() loads the user object into $account, but how do I access custom fields I've created on the user object (via the admin UI)? With dpm($account) I can't see any of my ...
19
votes
3answers
15k views

How can I get the node ID from a path alias?

I want to be able to get the nid but the only information I have is http://example.com/this-is-the-alias. Is there a way to get either the internal path of /node/* for that alias if I am not on the ...
16
votes
2answers
32k 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?
7
votes
2answers
7k views

I don't see Views Theme Suggestions

For some reason I don't see the views theme suggestions in my twig debug information? What do I miss? In my development.services.yml in set debug to true. I do see debug information and theme ...
6
votes
2answers
2k views

How to migrate multilingual image alt fields from CSV?

I'm migrating multilingual content to Drupal 8 from a group of CSV files, and I'm about 95% of the way there. I have an image field attached to an article content type that shares the image among all ...
4
votes
2answers
572 views

Development with git branches/ gitflow and new modules

I wonder if somebody found a solution for the following issue related to Drupal 8 development with Git branches: You work on a new feature in a local feature branch for that you activate a ...
4
votes
2answers
2k views

Passing current node ID to the block template

I have a module with a custom block MyCustomBlock.php that get the nid of the current page and pass the value to the block template: $node = \Drupal::routeMatch()->getParameter('node'); $nid = $...
3
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 ...
9
votes
1answer
1k views

Returning alternate HTTP codes for unpublished node

I'm trying to return the 404 page instead of 403 response for unpublished nodes in Drupal 8. I tested kernel response subscriber, but found the code I was using would only change the status code to ...
8
votes
2answers
14k 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: ...
6
votes
2answers
2k views

How do i force a text format and hide the format selector in a formatted text field?

I Want to force a certain text format in a user profile text format field and hide the text format selector dropdown. How do i do it? This is for Drupal 8.
6
votes
1answer
9k views

Programmatically update node image field (using URI of the image) and get URL in twig

I am trying to update a node image field programmatically. I currently loading the node like this: $node = Node::Load(1); have the URI if the image that I want to set. I have tried this but no luck: ...
5
votes
1answer
5k 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
4answers
7k views

Inserting the value from Datetime field form

I have a form where the user can input datetime and then I want to store it in the database. Here's my schema : 'start' => array( 'type' => 'varchar', 'mysql_type' => 'datetime', ...
1
vote
1answer
2k 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 ...
1
vote
1answer
472 views

Export Paragraph bundles

I know drupal config:export:content:type is for exporting a content type. Is there a way to do this for a Paragraph bundle? drupal config:export:paragraph:type doesn't work.
8
votes
4answers
3k views

How to make existing public files private?

Let's say I have a node type "Article" which has a field "File" which is set to handle public files. A lot of articles and files get added. Now the specs suddenly change and the "Article" will move ...
8
votes
1answer
4k views

Working with template suggestions on Drupal 8

I need Drupal to use a custom page template if the URL contains a particular _GET parameter. In D7 I would do something like this in the theme's template.php: function mytheme_preprocess_page(&$...
8
votes
3answers
7k views

How to test for a boolean field in a twig template?

field_boolean is a boolean field. {% if content.field_boolean == true %} or {% if content.field_boolean == 1 %} or {% if content.field_boolean == 'true' %} or {% if content.field_boolean == '1' %} ...
6
votes
1answer
6k views

form_state->setRedirect(to_a_new_node_page) from the submitForm function, route “does not exist” issue

I created a custom module, It generate a custom Form in a page. When I submit my form, I create a new node. So, I am redirect to the form page but I would like be redirect to the new node page. I add ...
4
votes
1answer
6k views

Override a single JavaScript file from a module

In my theme's libraries.yml file, after the global-styling section, i'm trying to replace one JavaScript file from the core Toolbar module (it's addition of padding-top to body interferes with our ...
4
votes
2answers
1k views

Selecting taxonomy term in article and showing all articles titles associated with this term

I have a content type article and when editing an article there should be a field where you can select a taxonomy term of a specific vocabulary. When viewing the article it should show a list of ...
4
votes
2answers
2k views

How can I dynamically add URL or taxonomy to body class

Am creating my own theme and have successfully added the URL into the node class in node.html.twig with {% set classes = [ 'url' ~ url|clean_class, ] %} but I need to be able to style each page ...
4
votes
1answer
5k views

Override theme template from module without implementing a theme

I have a project on D8 where I don't use any custom themes, I use default seven theme for everything because there is no need of any visual theming. So My question: Is it possible to override theme ...
4
votes
2answers
1k views

Cannot deal with multiple iterations of same form on one page

I am designing a site that has a variety of points in which I need to render "workflow" buttons that are used to send actions to an external application. I used the form API to generate these ...
3
votes
1answer
4k views

Drupal 8 function from controller returns html markups only

I have been creating a table from mysql result , but its printing the html markup only and says controller must return a response . what may be the reason ? LogicException: The controller must ...
3
votes
3answers
4k views

Alter the access of menu links 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
4k views

How do I run a site from a sub-directory?

Maybe I'm making this way more complicated than I need to, but I want to serve my Drupal site that I've installed at example.com/drupal from example.com. This particular site is an add-on site on my ...
2
votes
1answer
5k views

How do I submit a form via AJAX?

I'm using the Webform module for Drupal 8. The module confirmation settings for a form are the following: Page (redirects to new page and displays the confirmation message) Inline (reloads the ...
1
vote
1answer
275 views

hook_theme_suggestions_page() provide default template file inside module folder

I am using hook_theme_suggestions_HOOK() to implement a custom template file in my drupal 8 website like below. /** * Implements hook_theme_suggestions_HOOK(). */ function ...
12
votes
4answers
16k views

Running Drush returns an error

I am running Drush version 6.2.0 and the latest Drupal 8 beta on Dreamhosters. When I run drush cc all within the sites directory, I receive the following error immediately after executing the command:...
6
votes
2answers
3k views

Where is the “auto submit” option?

I have an exposed filter for one of my views and I added a drop-down select for the users to pick from. In Views for Drupal 7 there was an Auto-Submit check box, but I can not seem to find it in ...

1 2
3
4 5
35