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

New answers tagged

0

So after we ran regular update (current version was 8.6.10), our website crashed. We followed this fix to recover from WSOD https://www.drupal.org/project/drupal/issues/3039408#comment-13018093 After website was restored we tried running all kinds of composer commands to update (like mentioned in question) and it would just spit out "Nothing to install or ...


0

My issue was from improper checking of array key values. Below is the approach for non-ajax form adjustment (which is very similar to ajax). MYMODULE/src/Form.php: /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // get form config. $config = $this->config('MYMODULE.settings'); // Set our count. ...


0

I was having - public://2019-03/YxoEy6.png and I got the image by - <img class="item-logo" src="{{file_url(restricted_item.logo_name.logo )}}" alt="logo" />


1

It is also possible to do one-liner with magic method: $node->field_file->entity->getFileUri(); Or to render as string file_create_url($node->field_file->entity->getFileUri());


0

I use direct input parameter for right filtering, and it is working for me. $view = Views::getView('my_view_name'); $view->setDisplay('display_name_from_my_view'); $view->setArguments([ $value1, $value2 ]); $view->execute(); So, i can take result of $view by $result = []; if (empty($view->build_info['fail']) and empty($view->build_info['...


0

$query = $db->query('MY QUERY'); print_r($query); // In the result you'll see a key "queryString" containing the actual query


1

MYMODULE/src/Form.php: /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // get form config. $config = $this->config('MYMODULE.settings'); // Set our count. Used in for loop below. if (!empty($form_state->getValue(['fieldset', 'field_count']))) { // get $form_state count value. $...


0

As an easy workaround you should try downgrading your twig composer require twig/twig 1.37.1 Follow the discussion here and here for more up to date information.


0

Just thought it would be easier to show a basic example that has both parent and submenu item in the mymodule.links.menu.yml. Right now both links goto the same place (as I had to pick a default for the parent item, since I didn't have a admin page that lists all my custom links yet ... and also since having "route_name: <nolink>" did not work for ...


1

Just thought it would be easier to show a basic example that has both parent and submenu item in the mymodule.links.menu.yml. Right now both links goto the same place (as I had to pick a default for the parent item, since I didn't have a admin page that lists all my custom links yet ... and also since having "route_name: <nolink>" did not work for ...


0

Suppose you're in mysite.com/public and you want the index.php or drupal root should come directly under mysite.com/public then do this: Then execute: create-project drupal-composer/drupal-project:8.x-dev my_site_name_dir --stability dev --no-interaction --no-install now go to my_site_name_dir and move everything including * and .* to under mysite.com ...


2

In Drupal 8, timestamps (and created and updated) are stored as integers in the database. They do not use the native datatype. Timestamps can be added via the UI, but created and updated can only be used as basefields. Datetime and daterange fields are stored as ISO strings: date-only as Y-m-d and date+time as the full ISO8601 format (currently without ...


4

In Drupal 8, private file permissions by default are given according to the entity to which they are attached. If the user has permission to view the entity, they will have permission to view the file. If you are not attaching the file to an entity, then you will need to implement hook_file_download(), where you will determine whether or not the user has ...


1

From a Drupal perspective, timestamp has issues with Views Filters. In a recent D7 project, I went with timestamp just to keep things consistent since I was doing custom module date field queries. In D7 I noticed that View filters only works if you enter a timestamp rather than a date, this is silly! Which makes me think most people use date, since it ...


2

Files uploaded to managed files will be set as temporary. You need to set the file status as permanent, and add a usage, to prevent the file from being deleted. Setting files as permanent can be done using File::setPermanent(). File usages can be added as follows: $fid = 1; // The file ID $file = \Drupal\file\Entity\File::load($fid); $file_usage = \Drupal::...


0

The Logintobbogan module for Drupal 7 does something similar. It implements hook_form_alter() for the user password reset form, which is also used for processing the one-time login link sent in the confirmation email, to set $account->logintoboggan_email_validated to TRUE. In Drupal 8, it could be still possible to implement something similar. The ...


1

The easiest way to go since you have mentioned business rules module: Create a rule: Entity is viewed Create a Variable Data Comparison to check if [current-user:url:path] equal to [user:url:path] If Yes, DO NOTHING If No, Create a Page redirect action to the home page. Hope it will help,


2

Yes short Answer have a look at creating a custom twig extension: the idea would be to pass the details required as an "exclude from display" field (or fields) to the custom global text field. Note excluded from display fields can be accessed in the "REPLACEMENT PATTERNS" section under view text. then basically in the text field you would do something ...


0

Yep so your going to have to hook into the VOB results or submit function I assume you have already done this. then in your function you can create a Response such as the following: use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; $resultedTerms = [ 'terms' ...


0

Similar to other jQuery-related answers, you could add an function and call it for each form field or an entire form: function autocomplete_tid_remove(field){ var autocomplete_tid = $(field); var autocomplete_tid_stripped = $(autocomplete_tid).val().split(" ")[0]; $(field).val(autocomplete_tid_stripped); } ...


0

In Drush version > 9 it should be drush uli --name=USERNAME notice take a look at a digit after reset/{UID}/ is should be the id of user you've tried to reset in you case user/reset/1/ it obviously reset the password for used one. So if you want to do it for all user run the following command in your terminal : for name in $(drush sqlq "SELECT name ...


0

I am not sure why people down-voted my question. It might have been a little silly to ask if there's a way to alter the group by of a views query using hook_views_query_alter because I think aggregation is actually a part of the base query and not views. So instead of using hook_views_query_alter we need to use hook_query_alter. Ex. /** * Implements ...


4

The Entity Browser doesn't current pass current default value items field in persistent data, but it's easy to add it. 1) Add persistent data using field_widget_form_alter() /** * Implements hook_field_widget_form_alter(). */ function mymodule_field_widget_form_alter(&$element, FormStateInterface &$form_state, $context) { if (!empty($element['...


2

I used your default argument class and debugged a little. This is my approach: The entity browser widget stores selected values in its current property, which is filled, when the entity form is opened with an existing entity/selection. The widget also uses AJAX when the modal closes and the current property is updated accordingly. So you can get the ...


3

It is possible with just core views. Create a view that displays terms enable aggregation add relationship Content with term add sort content uuid with aggregation type: count add field content uuid with aggregation type: count add field taxonomy term Your view should look similar to the following


0

To append a term's name as CSS class to the term field itself you could simply implement template_preprocess_field() like so: use Drupal\taxonomy\Entity\Term; use Drupal\Component\Utility\Html; /** * Implements template_preprocess_field(). */ function MYTHEME_preprocess_field(&$variables) { if ($variables['field_name'] == 'field_MYFIELD') { ...


0

/** * Implements hook_ENTITY_TYPE_update(). */ function MODULE_user_update(Drupal\user\UserInterface $user) { if (!empty($user->original)) { // check previous value exists if($user->original->pass->value != $user->pass->value) { // check if pass changed $user->field_email_confirmed->value = 1; // set new value } } }...


0

For Node: {{ node.getOwner.field_first_name.value }} {{ file_url(node.getOwner.user_picture.entity.fileuri) }} {{ node.getOwner.uid.value }} For Comment: {{ comment.getOwner.field_first_name.value }} {{ file_url(comment.getOwner.user_picture.entity.fileuri) }} {{ comment.getOwner.uid.value }}


4

When you are working with CDNs and multiple layers of caches, it's very important to identify which caches is actually giving you problems. Out of the Drupal handles clearing caches itself in Drupal 8. So when you update a node, the page cache and render cache and all kinds of cache is cleared for that node alone. This means that when an editor updates a ...


0

To find a solution I would first check, if the information I want to display is in the actual render array. You can do this by using a variable dump. {{ dump(comments|keys }} or {{ dump(comments.author|keys }} (If you have devel with kint installed, you can use this vor variable dump.) Now you can look: If your first-name field is not in the render ...


0

I believe you did not install the module if you tried to install you would get drush en final ParseError: syntax error, unexpected 'final' (T_FINAL), expecting identifier (T_STRING) in /home/giorgos/share/gwebsites/dru8.dev/web/modules/custom/final/src/Controller/ExampleController.php on line 2 #0 /home/giorgos/share/gwebsites/dru8.dev/vendor/composer/...


2

The "Drupal way" is always a fuzzy term because there's usually more than one answer that works. Anyway, if you're looking for something less verbose, it would help to look at the File object and it's url() method. That saves you some steps and might save you some work down the road if the old D7 file module API functions get slated for depreciation (like ...


0

Finally and using advice from @Clive, I made it this way: public function submitForm(array &$form, FormStateInterface $form_state) { switch ($form_state->getValue('suscribe')) { case 0: $iStatus = 1; $sMessage = $this->t('Your wish has been recorded.'); break; case 1: $iStatus = 3; $Url ...


0

If you want to theme a specific form, for example the edit form of a node type, then all you have to do is /** * Implements hook_theme(). */ function THEMENAME_theme($existing, $type, $theme, $path) { return [ // form id (weather it's an edit node for or a new node form) 'node_NODE_CONTENT_TYPE_edit_form' => [ 'render element' => '...


0

You don't need a custom module for this. Drupal can have seperate language detection for interface (menu item/interface elements) and content. There was a bug that was fixed recently so make sure you are on the latest 8.6.x version. Assuming you have enabled all 4 core language modules and you have enabled at least 1 extra language than configure the ...


0

I was able to edit it using theme_preprocess_table method below is the method which I used. function theme_preprocess_table(&$variables) { $variables['header']['completed']['content'] = 'your requirement'; }


0

You can display information from nodes that are connected through Entity reference fields right in the Views interface. In your case you're referencing Resources from Projects, so you need to add the Relationship for the Entity reference field, then you will be able to add Fields that you can find on the Resources Content type (they will automatically use ...


2

Many thanks for @No Sssweat give a clue to me. her solution works for content types only. but for Taxonomy page and General pages ( custom pages you've created by custom route like me) the following snippet will work charmingly: on YOURTHEMENAME.theme file use \Drupal\taxonomy\Entity\Term; /** * Implements hook_theme_suggestions_HOOK_alter(). */ function ...


0

What was called NID in Drupal 7 is now simply ID under the Content Category in Drupal 8. To filter out specific nodes you need to add as many ID Filters (each Filter for the specific node) and then use OR operator in between them. Or you can use the Regular expression Operator in a single Filter that would "solve" for the exact node IDs you need. Here'...


2

Try changing your code to use hook_entity_insert which is run after the saving to the database: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21entity.api.php/function/hook_entity_insert/8.2.x As the reason you can't get the entity ID in presave is because if its a new entity then the ID hasn't been generated by the autoincrement ID ...


0

If you have a multiste installation, Copy /sites/development.services.yml to your subsite folder Rename it to be services.yml Open your settings.php and find the following line: $settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml'; Under that line add: $settings['container_yamls'][] = DRUPAL_ROOT . '/sites/YOUR_SITE>/...


2

You can add new templates to already existing using hook_theme_suggestions_HOOK_alter Example of adding a content type: /** * Implements hook_theme_suggestions_HOOK_alter(). */ function THEMENAME_theme_suggestions_page_title_alter(array &$suggestions, array $variables) { if ($node = \Drupal::routeMatch()->getParameter('node')) { $...


1

Two options: _image_fixed: - plugin: str_replace source: imageName search: "jpg" replace: "png" source_full_path: - plugin: concat delimiter: / source: - constants/source_base_path - @_image_fixed Or: source_full_path: - plugin: concat delimiter: / source: - constants/source_base_path - imageName ...


0

i have used parameter upcasting in routes to convert dynamic values in url to object instances https://www.drupal.org/docs/8/api/routing-system/parameter-upcasting-in-routes in a bloc template listing all publications <a href="/publication/{{ row.halId_s }}">call to publication detail</a> my_module.routing.yml , linking the route to the ...


0

I was a bit disappointed with using migration modules, and I quickly started using my own scripts. Below a script to import a taxonomy with hierarchy: // You would first have to create an array $results from csv or other source // Make sure you have tid, title and parent in your set foreach($results as $result) { Term::create([ 'tid' => $result->...


0

I could not get the default filter to work but I did have some success doing the following scary-ness: function mymodule_views_pre_render(\Drupal\views\ViewExecutable $view) { if ($view->id() == "media_entity_browser" && $view->current_display == 'entity_browser_1') { $request = \Drupal::request(); $prams = $request->query->...


0

This is what I do. I would only use it to increase the length of a string. I have not tested, but assume that shortening a string will truncate data. First, backup the database. Then, edit the structure of the following tables (change yourfield to match the name of your field): field_data_field_yourfield field_revision_field_yourfield Change the length ...


1

It's possible you are using the wrong hook. hook_preprocess_page() is not for the content type page. Use a preprocess hook for nodes and check the content type: function mymodule_preprocess_node(&$variables) { if ($variables['node']->getType() === 'page') { $view_mode = $variables['view_mode']; // preprocess only nodes of the content type "...


0

I would suggest an abstract base class, but instead of creating another function ::doSomethingCommon, partially implement ProcessQueueBase::processItem and call parent::processItem from the subclasses.


0

I needed to put a class based on view mode onto my pages. I seem to remember that view mode is handled separately from the node data. My solution was actually based on using the Display Suite submodule Switch View Mode (was already using DS). This module creates a new base field in the entity and sets the view mode to it. This let me use the following ...


Top 50 recent answers are included