Drupal StackExchange

Importing nested XML using Feeds XPath Parser

5 days 9 hours ago

I have some XML formatted as such:

<item> <title>Name</title> <id>12</id> <upgrade> <id>13</id> <level>2</level> </upgrade> <upgrade> <id>14</id> <level>3</level> </upgrade> </item>

Ultimately from this example I want 3 nodes:

  • Title: "Name (1)" GUID: 12
  • Title: "Name (2)" GUID: 13
  • Title: "Name (3)" GUID: 14

I'm quite happy to do 2 runs of the file if necessary. I have one importer at the moment which sets up the "Name (1)" items. This works perfectly.

I have a second importer set up which I can successfully create the secondary "upgrade" nodes but only if I use \item\upgrade as the context, at which point I lose the title element so the nodes come through as " (2)", " (3)" etc.

If I use \item as the context like the initial importer, I can't seem to loop through the upgrade XML nodes.

jamestsymp

Adding new rows on a draggable table via jquery

5 days 10 hours ago

I have a draggable table with preloaded "new items" - sorta like the Power Edit feature of the menu_editor module. Everything works perfect.

However, I want to have a button that adds a new row via jquery. I was able to do this via the following code. However, the new rows added by jquery are not draggable. What can i do to make it work? Is it even possible?

var preloaded_items_count = '.$preloaded_items_count.'; $("#edit-add-new-item").click(function(){ var append_tr = $("#guide-pages-table tr:last").clone(); var replace_pattern = new RegExp("new-" + preloaded_items_count, "g"); var new_item_id = "new-" + (preloaded_items_count + 1); //append_tr.find("a.tabledrag-handle").remove(); append_tr.html(append_tr.html().replace(replace_pattern,new_item_id)); preloaded_items_count = preloaded_items_count + 1; //Drupal.tableDrag.prototype.makeDraggable(append_tr); $("#guide-pages-table > tbody:last").append(append_tr); return false; });

Bibokid

Adding a validation step via hook_form_FORM_ID_alter()

5 days 12 hours ago

I am trying to add a custom validation function to an existing form. I am using hook_form_FORM_ID_alter() to edit the form. I am then adding a new function to the #validation array. When I use dpm() and print out $form['#validation'] I can see that my function is there. However the validation step is not running. If I dpm() in the validation function it is not hit.

/** * Implements hook_form_FORM_ID_alter(). */ function mymodule_form_mycustomdorm_form_alter(&$form, &$form_state, $form_id) { $form['#validate'][] = 'mymodule_test'; dpm($form['#validate']); } function mymodule_test($form, &$form_state) { dpm($form_state); }
Bobby

How to retrieve Apache Solr's current search filters?

5 days 12 hours ago

I'm using Apache Solr Search, Search API and Facet API.

Is there a way to retrieve the current search filters being used when using Apache Solr on Drupal?

For example: I have a website using facets which reference a taxonomy called colours. In this facet, there's a list of colours - if I select Green, this generates an Apache Solr search - using green as the filter.

www.example-website.com/?f[0]=field_colour%3A2712.......etc

When the Solr search is created - I guess, I could grab the term id 2712 from the URL using GET - but there must be a cleaner way.

Any ideas?

williamsowen

Webform two dependent select lists

5 days 14 hours ago

I have a content type "course" and a taxonomy vocabulary "Course categories" and a Webform "Register" the user will register by choosing the course category in select list then use the course related to this term .

Now i have a list for terms and a list for courses The problem is i don't know how to link between the two lists so the courses list show only the correct course

Eman Shaaban

alter query view by adding fields in an andGroup within an orGroup

5 days 14 hours ago

I have a multilanguage site with two languages: English and Dutch. Not all nodes are created in both languages. Some nodes even have no language ('und', 'zxx').

I want the default Drupal provided taxonomy view output all nodes of a taxonomy-term in the current and no node-language, AND, if present, other nodes of this term from the other language. The Drupal provided sql is:

SELECT "taxonomy_index"."sticky" AS "taxonomy_index_sticky", "taxonomy_index"."created" AS "taxonomy_index_created", "node_field_data"."nid" AS "nid", "node_field_data"."langcode" AS "node_field_data_langcode" FROM {node_field_data} "node_field_data" LEFT JOIN {taxonomy_index} "taxonomy_index" ON node_field_data.nid = taxonomy_index.nid WHERE ((taxonomy_index.tid = '14')) AND (("node_field_data"."langcode" IN ('nl', 'und', 'zxx')) AND ("taxonomy_index"."status" = '1')) ORDER BY "taxonomy_index_sticky" DESC, "taxonomy_index_created" DESC LIMIT 11 OFFSET 0

I want, if applicable, extend the where clause so it becomes by example:

WHERE (((taxonomy_index.tid = '14')) AND ((("node_field_data"."langcode" IN ('en', 'und', 'zxx')) AND ("taxonomy_index"."status" = '1'))) OR (("taxonomy_index"."tid" = '14') AND ("node_field_data"."nid" IN ('43')) AND ("node_field_data"."langcode" NOT IN ('en', 'und', 'zxx'))))

I wrote a function example_views_query_alter(ViewExecutable $view, QueryPluginBase $query) in which I found out which extra nodes should be added in the extra OR clause. By adding this code:

$group_id = $query->setWhereGroup('OR'); $query->addWhere($group_id, 'taxonomy_index.tid', $tid); $query->addWhere($group_id, 'node_field_data.nid', $missing, 'IN'); $query->addWhere($group_id, 'node_field_data.langcode', $langcodes2, 'NOT IN');

But in the extended where clause I get OR instead of AND statements:

WHERE ((taxonomy_index.tid = '14')) AND ((("node_field_data"."langcode" IN ('en', 'und', 'zxx')) AND ("taxonomy_index"."status" = '1')) OR (("taxonomy_index"."tid" = '14') OR ("node_field_data"."nid" IN ('43')) OR ("node_field_data"."langcode" NOT IN ('en', 'und', 'zxx'))))

But it should be an AND group within an OR Group, maybe like:

$query->setWhereGroup('OR'); $query->setWhereGroup('AND'); $query->addWhere(...

Who can help me out to achive this?

PROMES

Providing menu route parameter values from url

5 days 17 hours ago

Suppose I have the following route in my ej.routing.yml file:

ej.form.user.profile: path: '/user/{user}/ej_profile' defaults: _title: 'EJ Profile' _form: '\Drupal\ej\Form\User\ProfileForm' requirements: _role: 'authenticated' user: \d+

Now I want to add a menu based on the above route to Tools menu. So I use the following in ej.links.menu.yml file:

ej.user.profile: title: 'EJ Profile' description: 'EJ Profile' route_name: ej.form.user.profile menu_name: tools weight: 100

However this gives me an exception saying: Symfony\Component\Routing\Exception\MissingMandatoryParametersException: Some mandatory parameters are missing ("user") to generate a URL for route "ej.form.user.profile".

The same works as a task entry. Basically I have a custom form that extends user profile to integrate with a third-party system and I need the user id from the url to fetch appropriate user's information.

How can I have the menu to pick route parameter from the url?

r_honey

How to delete children when main entity is deleted?

5 days 18 hours ago

I am looking for the best way to delete children of my main entity when i delete it.

I have 2 entity type :

commandes_entity

commandes_ligne_entity ( entity reference to commandes_entity )

The only way i have found is to create a hook_entity_delete :

Edit : This is how i delete children :

function boutique_commandes_entity_delete(Drupal\Core\Entity\EntityInterface $entity) { $query = \Drupal::database()->delete('commandes_lignes_entity'); $query->condition('commandes_id', $entity->get('id')->value); $query->execute(); }

Is there another way (maybe better) for delete children ?

Kevin

Drupal Planet

Gábor Hojtsy: 15 reasons I am excited about Drupal's new Starshot initiative

5 days 17 hours ago
15 reasons I am excited about Drupal's new Starshot initiative

Drupal project lead Dries Buytaert just unveiled the Drupal Starshot Initiative and I couldn't be more excited! Starshot is all about putting users first. Enhancing Drupal core with additional components tailored to everyday users of the interface. Technically, it builds on Drupal core's robust foundation, utilizing Automatic Updates/Package Manager for seamless installation and maintenance, Recipes for the base system and on-demand additions, and Project Browser to help with recipe and extension discovery.

As I was talking to people about Starshot at DrupalCon Portland I realized it is easy to overlook how fundamental the changes proposed are in terms of how Drupal will innovate and the benefits end users will enjoy. At the same time those that did not have time to watch the whole keynote had understandable misconceptions about its nature. Some were concerned the fundamental changes are happening in the architecture, or a fork / parallel project is being set up. That is not where/how Starshot revolutionizes Drupal though. To address those misconceptions, I already worked on answers to frequently asked questions and published on the Starshot page.

This blog post will focus on the benefits that I see. I had the chance to participate in two hours of Starshot BoFs and then an hour long Q&A session at DrupalCon Portland. I also covered more technical details of Starshot's architecture in my Drupal 11 talk (including the most popular question on what the Launch button might lead to). Finally I had countless conversations with people at the event. Maybe confirmation bias, but there were only a couple people I talked to that were entirely skeptical. On the other hand I got very different viewpoints on what will the benefits be depending on who I talked to.

I think all of those are great, so I compiled them. Let's see 15 different reasons why I am super excited about Starshot and how it is very different from previous initiatives.

Gábor Hojtsy Sat, 05/11/2024 - 13:49