Drupal Planet

Drupal StackExchange

Export translations of field labels

6 days 10 hours ago

Drupal 7. I work on multi language site. I have a content type with entity translation fields. I've added translation to field labels and settings on my DEV copy of site and now I need to export and import it to Production.

Is there any module in Drupal 7, that helps me to export and import field labels/settings? Or maybe someone tell me, how to export values from "locales_source" and "locales_target" tables and import it to my Production database? Because I see only "lid" auto increment field in both tables.

Locales Source table

Locales Target table

dark_kz

How to use drush site-lists alias?

6 days 12 hours ago

I several folders containing symlinks to my drupal sites. I'd like to use this folder structure to create an alias so I can run commands on each group of sites.

I'm trying to do what "drush @sites status" will do, but on a smaller subset.

I wrote the following based on the docs

// List the instances from the OU instances folder $full_path = "/opt/drupal/sites/instances"; if ($handle = opendir("$full_path")) { while (false !== ($file = readdir($handle))) { if(is_dir($full_path."/".$file)) { if ($file != '.' && $file != '..') $instances[] = $file; } } } // Turn them into aliases so we just have to type @instance foreach ($instances as $instance) { $site_list = []; // Look at each instance $site_paths = $full_path . "/" . $instance; if ($file_handle = opendir("$site_paths")) { // List out the folders in this instance while (false !== ($site_folder = readdir($file_handle))) { if(is_dir($site_paths."/".$site_folder)) { // If the folder represents a drupal site if ($site_folder != '.' && $site_folder != '..') // Add it to this instances list $site_list[] = '@' . $site_folder; } } } $aliases[$instance] = array( 'site-list' => $site_list, ); } print_r($aliases);

The cheeky print_r on the end shows my array as

[partnership] => Array ( [site-list] => Array ( [0] => @www.1.co.uk [1] => @www.2.org [2] => @www.3.org.uk [3] => @www.4.org [4] => @www.5.eu [5] => @www.6.net [6] => @www.7.com [7] => @www.8-ri-2020.eu [8] => @www.9.edu [9] => @www.10.ac.uk [10] => @www.11.org [11] => @www.12.ac.uk [12] => @www.13.co.uk [13] => @www.14.org.uk [14] => @www.15.ac.uk ) )

I've changed the names to protect the innocent, but they are valid aliases.

When I run "drush @partnership status" I get

drush @partnership status You are about to execute 'status' non-interactively (--yes forced) on all of the following targets: Continue? (y/n): y Invalid argument supplied for foreach() backend.inc:661

How do I get drush to actually run through this alias list telling me the status of each site?

Stuart Crouch

How can I change the default system message shown on form submission

6 days 13 hours ago

I've created a business card request form as an EntityForm and am scratching my head trying to figure out where in the module i can find the line - ( " The submission has been saved " ) .

This message displays after every form submission/edit/save, and I would like to get rid of it but cant figure out where its coming from ! :)

Manny Adumbire

Receiving notifications when user edits a node?

6 days 14 hours ago

Newbie here! I'm running a site on Drupal 7 (iloveqatar.net) and users have the ability to submit their own content (News, Events, etc...).

I'm facing a couple of issues.

1) When users submit new content that's in moderation to be approved, I don't get any notification. What's the best module to a) send emails to moderators / admins so they're aware there is content that needs to be approved and b) Display the notification on the site (like an unread message counter).

Right now I click on "Needs Review" on the admin bar on the top of the site every few hours just in case theres new content.

2) This one is the more problematic issue. When a user submits an event for example, and it's then approved, the user still has the ability to edit his/her post, which then creates a draft that needs to moderated and approved. However since it's creating a draft of an existing note, I'm not seeing it under the 'needs review' table. I actually have to go to that specific event and then edit it to approve the changes. Of course that's no good for me, because I can't go around checking every single post just in case there's an edit.

Does anyone know of a solution for this so that I can get notified and/or it shows up in 'needs review' ?

Please do let me know if I need to include any additional information to get help.

Thank you so much in advance!

amnesia

How to display custom fields of taxonomy in field twig

6 days 15 hours ago

In my content type for Event, I have an entity reference called Speakers which refers to a taxonomy called Team Members. It's set to multiple so I can say which speakers belong to my event. On the event detail page, I want to list the speakers out with all of their fields.

I have a field hook called field-field-speakers.html which lists all of the speakers. I can't seem to get any of the fields within the taxonomy. (ex: item.content.field_job_title ). It doesn't display any content.

{% for item in items %} <div class="member"> <div class="name-box"> <div class="name"> {{ item.content }}</div> <div class="position">{{ item.content.field_job_title }}</div> </div> </div> {% endfor %}

How do I do this? I think the answer might be in a View but not sure how to map it dynamically based on which event I am in.

bb2j3z

Access field formatter settings in a field type plugin

6 days 15 hours ago

How can I get the field formatter settings inside a field plugin? The field plugin extends FieldItemBase and the corresponding field formatter plugin extends FormatterBase.

If there is no direct way, maybe I could use the entity_display.repository service. But to use the getViewDisplay I need to know which view mode is used. I don't know either how to get the current view mode in the field plugin.

The field plugin is a computed field that makes a calculation depending on some variables. I wanted to set theses variables as the formatter settings. But maybe this is the wrong approach. Maybe it would be better to use module settings for this purpose?

Mike

How do you override the add or edit node for a particular content type

6 days 16 hours ago

I want to format the editing or adding form for the article content type. i.e. node/add/article path and editing the same article.
I copied over the node-edit-form.html.twig template from core/modules/node/template and renamed it node-edit-form--article.html.twig.
I also tried node--article-edit-form.html.twig and some other flavors.
I can override the node.html.twig file by simply copying it to my themes template folder.
But since I couldn't get the edit file to work I also tried overriding the form alter function by adding this in my theme file.

use Drupal\Core\Form\FormStateInterface; function newsass_form_node_form_alter(&$form, FormStateInterface $form_state) { $form['#theme'] = ['node_edit_form']; }

This code is from here- How to override node add template for custom content type?

I added some text on top of the code, but I still can't get the article 'edit' or article 'add' page to display the text.

Drupal 8.6.1, and have debugging enabled. Full explanation of requirement: I have a user entity reference field in the article content type with a list of users that the article can be assigned to. For the most part they have an 'article' role. But if the person leaves, their role will be changed to 'Away'. The article can/will still be assigned to them but I need to indicate that they are no longer with the company or 'Away'. Within views entity reference I am able to re-write the user with the users role but this information doesn't get back to the entity reference field in the editing node. I thought of editing the article node and adding a hook to call the assigned users role..... Which I still need to figure out how to do. With debugging I tried suggested template page--node--add--article.html.twig but I still couldn't get the content revealed and yes I cleared cache. Using page level though doesn't allow granularity for each field.

QUESTION: By mytype is that the machine name of the entity reference field in the content type? I am also not quite understanding this function, where is the call to query the roles? I enabled kint and added this to the function.

kint($elements); die();

but get nothing returned. How do I check if this function is actually being called.
I tried something else also. I have users in the entity reference and in the entity reference views for users I added the roles, made them hidden and rewrote the users to include the roles. I works nicely in the views preview, but the roles detail doesn't get carried back to the content type add/edit pages.

Dupls

Change field value with hook_views_pre_render()

6 days 17 hours ago

I'm using Views in 8.4.0 and attempting to change the output of a field value with hook_views_pre_render(). The default value of the field is a node ID. The intent is to replaced the value with a static string depending on a whether or not it's contained in a predefined array using in_array().

The aforementioned is relatively straightforward.

I begin by looping through the results:

for ($i = 0; $i < count($view->result); $i++) { if (isset($view->result[$i]->node_field_data_node__field_lesson_nid)) { $viewed = in_array($view->result[$i]->node_field_data_node__field_lesson_nid, $viewed) ? 'yes' : 'no'; // Replace the default Node ID value with $viewed. ... } }

The array $viewed contains a list of predefined node IDs. If the node ID exists in the array "yes" is output otherwise "no".

The problem is how to output the value for each row of results within the View object.

I tried the following at the above ellipsis:

$view->field['nid_2']->options['alter']['text'] = $viewed; $view->field['nid_2']->options['alter']['alter_text'] = TRUE;

"nid_2" is the token for node_field_data_node__field_lesson_nid.

The problem is this changes the field value for every row. The last row in the results determines the value. (The View also has multiple joins (relationships) which further compounds the complexity.)

So my dilemma is where to replace the value within each row of the $view->result.

bacteriaman

Is there a way to remove cache tags from a render array

6 days 17 hours ago

When I turn on cache debugging, I see a lot of cache tags for render arrays that don’t make sense.

I don’t see an obvious way to remove these cache tags. For example, they don’t seem to appear in the $vars for the render array during a preprocess hook.

Are there ways to remove these cache tags?

miwayha