Drupal StackExchange

Create an SVG using data from Views

4 days 4 hours ago

I am looking for a way to create a dynamically-generated SVG graphic based on data returned in a view from the Views module. Since Views creates lists and SVG is ultimately XML and therefore DOM-based, they seem perfectly well-suited to work together.

I have seen a few posts around saying that SVG support/integration in Drupal is very limited, and I have only ever seen Javascript used to create an SVG and then manipulate it's DOM. There are some popular javascript libraries already in use, such as Raphaël and svgweb.

Has anyone seen PHP used to do this as well? I have seen the SVG Embed module but it's very new, hasn't been updated since July, and almost nobody is using it.

Does anyone know of a better way to integrate SVG and Drupal Views?

diekunstderfuge

How to fix issue with scheduling Rules component evaluation [closed]

4 days 4 hours ago

I am trying to schedule a component for evaluation in Drupal 10

I routinely do this in Drupal 7. But in Drupal 10, the component is not being scheduled.

See steps taken below:

Rules module installed Rules Scheduler submodule enabled

Configured a component (type action) to send an email

Next step was to configure the Rule. Added event: After saving a new content item entity Added action: Schedule component evaluation (this involves providing the component key and scheduled evaluation time.

After the Rule is fired, and the Schedule tab is visited, the component is not found there.

seyi

Add cardinality_unlimited taxonomy reference to custom entity

4 days 5 hours ago

Okay, so I'm getting an error that I think may be a Views bug, but I don't have enough knowledge about Views & SQL right now to be sure about that.

Here's the hook I'm using to install the new field into the poll entity, using drush entity-updates:

/** * Implements hook_entity_base_field_info(). */ function mymodule_entity_base_field_info(EntityTypeInterface $entity_type) { if ($entity_type->id() === 'poll') { $fields['cat'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Category')) ->setDescription(t('Category of poll')) ->setSetting('target_type', 'taxonomy_term') ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) ->setDisplayOptions('form', array( 'type' => 'entity_reference_autocomplete', 'weight' => -10, 'settings' => array( 'match_operator' => 'CONTAINS', 'size' => '60', 'autocomplete_type' => 'tags', 'placeholder' => '', ), )) ->setTranslatable(TRUE); return $fields; } }

Then, I make a view that would like to use this taxonomy term as a Contextual Filter. I want to use the taxonomy term name rather than the ID, so I need to add a relationship. I add relationship in the view and look for the Taxonomy Term relationship that has my description, "Category of poll" and select it. The view complains about a SQL error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'poll__cat.cat' in 'on clause': SELECT poll_field_data.id AS id, taxonomy_term_field_data_poll__cat.tid AS taxonomy_term_field_data_poll__cat_tid FROM {poll_field_data} poll_field_data LEFT JOIN {poll__cat} poll__cat ON poll_field_data.id = poll__cat.entity_id AND poll__cat.deleted = :views_join_condition_0 LEFT JOIN {taxonomy_term_field_data} taxonomy_term_field_data_poll__cat ON poll__cat.cat = taxonomy_term_field_data_poll__cat.tid LIMIT 5 OFFSET 0; Array ( [:views_join_condition_0] => 0 )

The reason for the error in the above query is that the poll__cat.cat column does not exist, but it rather SHOULD be poll__cat.cat_target_id.

My question is: is this a views bug or a bug with the way I'm adding the field to the poll entity, and if it is a views bug:

  1. How do I debug it? Where does views set the column name it's looking for?

  2. Is there a hook I can use to change it, and/or should I submit this odd case to the views project?

EDIT: I'm trying to use hook_views_query_alter and hook_views_pre_execute to try and modify the broken query to do what I want it to do, but it is incredibly frustrating, because all of the things are protected, and it is very inconvenient to access anything, considering the purpose of these hooks is to modify data. I'm trying to look through the functions for ViewExecutable and the views Sql class, but I don't see anything that will help me change the column to what it should be! Anyone who can help in any way, I will be so grateful.

Edit 2: It seems like this guy: Views doesn't like multiple entity references in my entity has had a similar problem. I feel like this is a bug somewhere, or at the very least an issue with CARDINALITY_UNLIMITED being confusing to implement with entity references.

RaisinBranCrunch

How to extend TableSort class

4 days 6 hours ago

I have a paged table that extends the TableSort class. The thing is, I would like to add some special parameters to the header links, so I need to extend the TableSort class. The problem is, it is not recognizing my new extended TableSort (MyTableSort) class. This is the code, any help would be greatly appreciated:

<?php // $Id: RadiosDemo.module $ //This module demonstrates the radios default value problem. class MyTableSort extends TableSort { /** * Compose a URL query parameter array for table sorting links. * * @return * A URL query parameter array that consists of all components of the current * page request except for those pertaining to table sorting. */ public function tablesort_get_query_parameters() { return drupal_get_query_parameters($_GET, array('q', 'sort', 'order', 'nid')); } } /** * Implementation of hook_menu(). */ function RadiosDemo_menu() { // Added a link to navigate to the demo node display page $items['RadiosDemo/Problem'] = array( 'title' => 'Demo of Pager Problem', 'page callback' => 'RadiosDemo_displaynodes', 'access callback' => TRUE, 'type' => MENU_NORMAL_ITEM, ); return $items; } /** * Function which will display all the nids in a paged table */ function RadiosDemo_displaynodes() { $headers = array( array('data' => 'nid', 'field' => 'nid', 'sort' => 'ASC'), array('data' => 'status', 'field' => 'status'), array('data' => 'title', 'field' => 'title'), ); // Select nid from published nodes with 20 pager limit $query = db_select('node', 'n') ->condition('status', 1) ->extend('MyTableSort') ->extend('PagerDefault') ->orderByHeader($headers) ->limit(30) ->fields('n', array('nid', 'title', 'status')); $results = $query->execute(); $rows = array(); foreach ($results as $result) { $row = array(); $row[] = $result->nid; $row[] = $result->status; $row[] = $result->title; $rows[] = $row; } $html = theme('table', array( 'header' => $headers, 'rows' => $rows, )); $html .= theme('pager', array( 'parameters' => array( 'banana' => 'banana' ))); return $html; }
SN_26

Custom form values in hook_form_alter() not available in custom validate function

4 days 7 hours ago

I'm modyfing a node form to add a few extra fields. On submit, I need to program some extra logic to these values then save them to the node object.

function module_form_alter(&$form, &$form_state, $form_id) { if($form_id == 'my_node_form') { $form['custom_form'] = array( '#type' => 'textfield', '#title' => t('Custom field'), '#default_value' => 'enter custom text here', ); $form['#validate'][] = 'custom_form_process_values'; } } function custom_form_process_values(&$form, &$form_state, $form_id) { echo '<pre>' . print_r($form_id,1) . '</pre>'; echo '<pre>' . print_r($form_state,1) . '</pre>'; exit(); }

When I go to node/22/edit and change "enter custom text here" to something else, and I submit the form, I only ever see "enter custom text here" and not the new text I entered. It seems that it does not carry the text through to the validate function. Also tried it in a submit function but the same problem occurs.

Why does this happen?

Luke

How to avoid url conflict when defining menu items, and make sure path without wildcards will be used in favor of path with %?

4 days 8 hours ago

In hook_menu, I have

$path = "events" $items[$path] = array( 'title' => t('Events'), 'page callback' => 'my_events_page', 'access arguments' => array('view my events'), 'type' => MENU_NORMAL_ITEM, 'file' => 'my_events.pages.inc', ); $items[$path . '/past'] = array( 'title' => t('Past events'), 'page callback' => 'my_events_past_page', 'access arguments' => array('view my events'), 'type' => MENU_NORMAL_ITEM, 'file' => 'my_events.pages.inc', ); $items[$path . '/%'] = array( 'title' => t('Events'), 'page callback' => 'my_events_page', 'page arguments' => array($depth), 'access arguments' => array('view my events'), 'type' => MENU_CALLBACK, 'file' => 'my_events.pages.inc', );

They were working, but not now.

If I change $items['events/past'] to $items['events/past1'], it works.

Does it mean I have path conflict? If so, how can I resolve it?

Rows in my {menu_router} table are as follows:

path: events page_callback: views_page (but I set it to xxx_events_page in hook_menu) fit: 1 include_file: empty (should not be empty) -- path: events/% page_callback: xxx_events_page (good) fit: 2 include_file: a file path is there -- path: events/past page_callback: views_page (but I set it to xxx_events_past_page in hook_menu) fit: 3 include_file: empty (should not be empty)

If I update the page_callback and include_file it works. If I clear the cache, everything set back to default.

kenpeter

How can I theme webform?

4 days 9 hours ago

I've got a website with a custom theme who was developed by an external group. I would like to custom the webform appearance.

In my form, there are grid fields. And these grid fields need to have a description. But in my custom theme, the description appears under the grid and I would like it appears just between the label and the grid. I hope you see what I mean.

In the theming.txt it seems that I have to edit the webform-form.tpl.php and save it to my theme folder. But in this file, there are only PHP code. So, how can I modify the HTML structure?

Dude

Order receipt email content

4 days 10 hours ago

I have a Drupal 8.6.7 site with Commerce 8.x-2.11 installed. I would like to include slightly more information in the emails sent out when customers complete the checkout process. I would like to reference both the equipment category field and a more general category field present in both the product and product variations.

At the moment I just see the Title, Unit Price and Quantity if I look at the list of orders (all tests right now) at /Administration/Commerce/Orders.

Is there a way of adding these fields through the web admin GUI so that they end up in an order receipt email? I also have 'MIME Mail' and 'Mail System' modules installed if that helps.

Pete L

Drupal Planet

Tag1 Consulting: 4 Important Improvements to Drupal Core Performance

4 days 9 hours ago

Curious about Gander and its potential impact on your workflows and site performance? This testing framework was instrumental in four important improvements made to Drupal core performance. Let’s break down each bottleneck and the solutions that led to these improvements. Learn more about this framework that provides a sophisticated way to detect and correct performance issues.

janez Wed, 05/01/2024 - 09:03