Problem with dependency injection (File::load and Drupal::service)

Problem with dependency injection (File::load and Drupal::service)

In order to make a managed_file field permanent I did this in my module configuration form: <?php namespace Drupalmy_moduleForm; use DrupalCoreFormConfigFormBase; use DrupalCoreFormFormStateInterface; /** * Class MymoduleSettings. */ class MymoduleSettings extends... read more
Problem with dependency injection (File::load and Drupal::service)

How to override registration form message

I should override registration form message “Registration successful. You are now logged in.” with String Overrides module it does not work, because new text is long and every line with other style, it is in Drupal 7 I try to do it in template.php , but no... read more
Problem with dependency injection (File::load and Drupal::service)

Is there a way to add node grants to anonymous users?

I want anonymous users to be able to access nodes that are promoted to the front page. (They can’t access to nodes that are not promoted.) It seems hook_node_access() isn’t seem called for anonymous users. I tried using hook_node_grants() and... read more
Problem with dependency injection (File::load and Drupal::service)

Is it possible to modify help text on a vocabulary page?

I am using a custom way of managing relations between terms in a particular vocabulary so I want to disable (or at least hide) the built-in functionality allowing terms to be placed in a hierarchy. I have managed this to some extent with CSS (managed by the module... read more
Problem with dependency injection (File::load and Drupal::service)

How to pass theme variables in #theme in a form element?

I need to pass product variable defined in hook_theme() and invoked in #theme but not sure how to pass product variables in #theme Please suggest. function storeinv_theme() { return array( ‘storeinv_pickup’ => array( ‘variables’ =>... read more
Problem with dependency injection (File::load and Drupal::service)

Adding custom data to the node object

I have created a content type called providers and when editting said content types users can fill in extra information related to the content. I have included said form fields using hook_form_alter, and the appropriate hook for _submit applied with it all working... read more
Problem with dependency injection (File::load and Drupal::service)

Is there a way to change Views base table dynamically?

I have a couple of Search API indexes for different server environments (test, qa, uat, prod) with different configurations. Instead of create 4 views in the admin, I just want to use one, and depending on environment, swap the base table (index). That way I can have... read more
Problem with dependency injection (File::load and Drupal::service)

Using cache for twig variables in preprocess function

I implement a menu on a region using a preprocess function to get a link with an anchor for each block of it with a title. I made a preprocess function for region, in my theme, where I test the region machine name. I first used the... read more
Problem with dependency injection (File::load and Drupal::service)

How do I say to Twig where to look for the template files?

I want to add another path where the templates are stored. In standard PHP I’d use $loader->addPath(‘../path/to/templates’). I found Twig_Loader_Filesystem::addPath(), but I have no clue where and how to use it. Is there any hook? read more
Problem with dependency injection (File::load and Drupal::service)

Get node URL path using entity query

I want to get a node path/URL via entity query. So far I’ve managed to fetch the title of the node. $facultyPostings = $query->get(‘node’) ->condition(‘status’, 1, ‘=’) ->condition(‘type’,... read more
Problem with dependency injection (File::load and Drupal::service)

Is there a workaround to post inline JS code at any time?

In Drupal 7 this worked: drupal_add_js(“jQuery(document).ready(function () { console.log(‘Hello!’); });”, ‘inline’); which aims to print the messages from the PHP code onto DevTools JS console in realtime (on each page request),... read more
Problem with dependency injection (File::load and Drupal::service)

Posting Data to an external site using APIs [closed]

I’ve been tasked with posting information from our website to recreation.gov, using their API http://usda.github.io/RIDB/ Is there a specific way using any sort of drupal module or built in PHP with drupal to do this? I’ve not done it personally in the... read more
Problem with dependency injection (File::load and Drupal::service)

Node value from form state

I have a node which I want to update from a form states values. I can set each value individually like: $node->set(“foo”, “bar”); Is there a way to mass assign the values instead of setting each individually? read more
Problem with dependency injection (File::load and Drupal::service)

how to test if a node is flagged in twig

I would like to know how to test if a node is flagged. In D7 : if ($ flag-> is_flagged ($ node-> nid)) But I discover D8 and I do not see how to do it with twig thank you in advance read more
Problem with dependency injection (File::load and Drupal::service)

How to use a terminate kernel event to log page access statistics?

In Drupal 7 hook_exit is implemented in the Statistics module to gather statistics for page accesses. This change record suggest the equivalent in Drupal 8 is to listen for kernel.terminate events. Here’s my code: /mymodule/mymodule.services.yml services:... read more
Problem with dependency injection (File::load and Drupal::service)

How do I create a cache context in Drupal 8 that varies on user/node field data?

Let’s say I have a complex render array that has two variations that depend on a simple if: whether the logged in user can edit a node inside it. There are two scenarios I look for: The node was created by the logged in user, or: The node’s field_group... read more
Problem with dependency injection (File::load and Drupal::service)

Get page title form url

I have an url like this: http://drupal.dev/en/news-events It’s not my current page url. How can I get the page title by using above url ? read more
Problem with dependency injection (File::load and Drupal::service)

How to add AJAX call back from another AJAX result in a form

I want to use 2 AJAX call back within a form. The scenario is like I am having a text field and a Search button which is defined in the form alter function. After entering a text and clicking on the Search button, will display some matching strings with some other... read more
Problem with dependency injection (File::load and Drupal::service)

Add attributes like id to block level elements in CKEditor?

In Drupal 8, is there a way/module to add attributes like “id” to h1-h6, p, span and so forth? I am trying to find a way to support anchors, which Drupal does not seem to support anymore. edit: Yes, I can instruct to edit with the Source button, but I am... read more
Problem with dependency injection (File::load and Drupal::service)

Display custom user profile field as name in articles

I would like to display the custom user profile field name as the author’s name in articles, instead of the user’s username. How can I do this without modifying code of my template or Drupal itself? I saw solutions for Drupal 7 but I’m using Drupal... read more