Correctly cache route by dynamic parameter

1 week ago

I have a route with an optional parameter like:

/foo/bar/{baz}

{baz} is optional.

When accessing that route by a value for baz, the page contents are correct, but the breadcrumb is incorrect and caches the first one that you visit. This makes the breadcrumb incorrect. These are paths that are accessible in the admin area only.

Is there a way to make the breadcrumb correct?

Edit: is the route cache wrong or the menu cache?

Kevin

How can I clear all check boxes on failed validation?

1 week 1 day ago

I have form with check boxes. The user checks the boxes and hits the submit button. If validation fails an error message is displayed. I also want all of the user's checks to be cleared so they can try again. Here's my code, but it does not clear the checks? Thanks.

/** * Defines a form. */ function my_form($form, &$form_state) { $form['alerts'] = array( '#type' => 'checkboxes', '#options' => $options, ); // the rest of my form if (isset($form_state['clear_checkboxes'])) { $form_state['values']['alerts'] = array_fill(0, count($form_state['values']['alerts']), 0); } return $form; } /** * Form validator. */ function my_form_validate($form, &$form_state) { // if validation fails set error message $form_state['rebuild'] = TRUE; $form_state['clear_checkboxes'] = TRUE; }
dbj44

How can I show a block based on the language users prefer to use?

1 week 1 day ago

I want to show a block to visitors based on their browser language. (I guess it should be based on the Accept-Language HTTP header).

The page should stay in English but there should be something like this site is available in your language, click here translated into the relevant language.

How can I achieve this?

user49

Alter views contextual filter field

1 week 1 day ago

I have two content types, Brand and Sector. Brand have a sector field which is an Entity reference field.

I have views that display the list of Brands and it has a sector contextual filter which displayed as an input field where you have to input a node ID.

I was trying to make it a dropdown with sector titles for a user friendly experience but wasn't able to achieve this in views. So I decided to alter the views form but it seems like that it's not working the same as in D7.

What's the right way to alter the views field or is there a way to render a field as dropdown using views?

Vlad Stratulat

How to resolve lazy_builder error?

1 week 1 day ago

We have a field that is an Entity Reference to Blocks. In our situation, this field is referencing a View block. We are able to add this field on the content type and node properly, but when the page renders there is the following error message. We set this up using steps from Drupal 8: How to Reference a Views' Block Display from a Field.

Uncaught PHP Exception DomainException: "When a #lazy_builder callback is specified, no properties can exist; all properties must be generated by the #lazy_builder callback. You specified the following properties: #attached." at /mnt/www/html/netscout/docroot/core/lib/Drupal/Core/Render/Renderer.php line 333

How would we resolve this issue?

What we have tried:

  1. DomainException with #lazy_builder and ['#cache']['keys'], but this did not have anything that helped because we do not load the block by using #lazy_builder
  2. We tried updating our modules, but still get the error message
  3. Tried removing the removing the block reference, but then we were not able to add the view block to the page.

We are using Drupal v8.5.3.

usernameabc

How to run custom function after clicking next on a multi page webform

1 week 1 day ago

I've created a multi page webform and I want to run a function after the user clicks the 'Next page' button on the first page only. After the user fills in the data on the first page, I want to grab that data and do stuff with it. After that the webform should work like normal on through the submission process.

How can I do this so that the function runs only once? I've tried using hook_form_alter and testing the value of $form['details']['page_num']['#value']. This value is 2 if I'm on the second page. For some reason the function fires twice and I can't figure out why.

Thanks

Tim Wooten

The file names are not transliterated on upload

1 week 1 day ago

I am using Drupal 7 and have transliteration module enabled.

I have a file field and I want to have the names of the uploaded files to be transliterated on upload.

The url alias for the nodes are well transliterated. But the file names are not.

I checked the settings for file system. The current settings are:

  • Transliterate file names during upload.(checked)
  • Lowercase transliterated file names. (checked)

If I "Transliterate existing file names" (admin/config/media/file-system/transliteration) then the names of the files I have already uploaded are transliterated. But still, when I upload new files, the file names are not transliterated.

Any ideas why the names are not translated on upload?

turzifer

How to programmatically create a custom panel pane

1 week 1 day ago

I created a custom panel layout with Panels 3 (following this excellent link) and my layout is ready. Now I have my static markup ready for a node (I can use it on the article or a custom content type) and I want to find out how to create a custom panel pane programmatically. I don't won't to do it through the UI as I want to totally control the dynamic markup of a node. to make things specific (but keeping a certain level of generality), imagine

<div class="post"> <h3 class="title"> <span class="date"> <span class="day"> !!php dynamic day of the date!! </span> <span class="month"> !!php dynamic month of the date!! </span> </span> <a href="#"> !!php dynamic title of the node!! </a> </h3> <div class="content"> <p> !!php dynamic content(body) of the node!! </p> <div class="read-more" > <a href="#"> !!php dynamic read more text!! </a> </div> </div> <!-- end: content --> </div> <!-- end: post1 -->

How can I achieve to manage the above dynamic node (and let's suppose I want to achieve an exact, specific markup)?

Vagelis Kostopoulos

How to redirect the checkout complete page?

1 week 1 day ago

In my Drupal Commerce site, I redirect to a local payment API with a custom module after the user selected the local payment gateway in the review order page. The users enter username and password in the local payment website; if the user is authenticated successfully, the payment gateway server redirects back to my localhost at http://localhost/commerce/sites/all/modules/paymentgateway/CheckoutComplete.php.

In that page, the pay button exists; the user has to click the pay button to finish the payment transaction. After finishing payment, I want the server to redirect to Drupal Commerce's checkout complete page, e.g. http://localhost/commerce/checkout/93/complete.

How do I redirect to this link? Do I have to implement a hook?

SAWAUNG

Add a user/author field formatter

1 week 1 day ago

i have a site where I use display suite for custom page display. And all works. Now I need to add a custom field formatter for the "Author" field, but I don't find how to link "author" to a new field formatter.

I know that I need to use hook_field_formatter_info() but I don't understand which is the right value for "field types". I have tried with "user", "user_reference", "text","author" but nothing.

I have tried to see how Display Suite define its fields formatter, but for this field the module use "2" for this value:

$fields['node']['author'] = array( 'title' => t('Author'), 'field_type' => DS_FIELD_TYPE_FUNCTION, 'function' => 'ds_render_author_field', 'properties' => array( 'formatters' => array( 'author' => t('Author'), 'author_linked' => t('Author linked to profile') ), ), );

where

define('DS_FIELD_TYPE_FUNCTION', 2);

So how can I add one new field formatter for the author field ?

Thanks.

ZioBudda

Duplicate entry/Contraint violation 1062 in file_managed on browser crash

1 week 1 day ago

I'm using Drupal 7.28. Today when I tried to upload some 100 image files in Image field type, it aborted in the middle saying that "20 MB" limit reached. Now it wouldn't even show me way to delete the files.

Since then I'm getting the following error (below). when I try to upload the same files.

I've run cron and also cleaned all caches but this error does not go.

I can see that these orphaned files are still stored in the file_managed table.

How can I resolve this problem?

Related post: https://stackoverflow.com/questions/8809010/pdoexception-on-duplicate-filename-in-drupal-7

Another solution comment here on Drupal.org which says that such files should be cleaned by 6 hours by Cron run.

Error on repeat uploads

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'public://wsgallery/DSC00441.jpg' for key 'uri': INSERT INTO {file_managed} (uid, filename, uri, filemime, filesize, status, timestamp, type) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => DSC00441.jpg [:db_insert_placeholder_2] => public://wsgallery/DSC00441.jpg [:db_insert_placeholder_3] => image/jpeg [:db_insert_placeholder_4] => 305012 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => 1413799461 [:db_insert_placeholder_7] => image )

AgA

In code alter user registration and override approval to no approval required

1 week 1 day ago

In my module I want to override the approval for certain users so that they are immediately approved and get the corresponding email.

The module looks at the subdomain to decide if approval is required. If it is, then the register-with-approve email should be sent. If no approval is required, the account should be activated and the no-approval-required email should be sent.

I have looked for hooks that I could use for this, but haven't got anything working yet. I'm using Drupal 7.

Whiskey

How to programmatically render a webform to display specific Elements

1 week 1 day ago

I have tried this way but not able to hide "confirmation_id" element.

public function buildForm(array $form, FormStateInterface $form_state, $sid = NULL) { $my_webform_machinename = 'request_form'; $my_form = \Drupal\webform\Entity\Webform::load($my_webform_machinename); $my_form['elements']['flexbox_layout']['confirmation_id']['#access'] = FALSE; return [ 'form' => [ '#type' => 'webform', '#webform' => $my_form, '#sid' => $sid, ], ]; }
Drupal Dev

Group date field by day for chart

1 week 1 day ago

I have a custom database table with a datetime column that I have made accessible to Views. I want to create a line charts of number of rows per day but I can't get the View right.

With aggregation on I have a COUNT on my ID field and I'm trying to group on my date field by day (it currently has year -month - day - hour - minute - second). I have set the date format to d/m/Y and aggregation to group results together but they are still separate.

Obviously this makes for a pretty bad line chart

What I really want is

18/01/2017 23 19/01/2017 25 20/01/2017 19

I tried the Views Date Format SQL Field module (dev version too) but it doesn't seem to work as I don't get an option to format my date as SQL.

Is this possible in Views?

nexus_6

Commerce PayPal wps sends to and gets data from sandbox but no payment method available

1 week 1 day ago

I'm on localhost without ssl and fix IP. I can checkout with PayPal WPS, go to sandbox, confirm as buyer, and when I click in the sandbox I go back to my testsite after confirming to leave SSL.

In my logs I can see (watchdog) that the function commerce_paypal_wps_redirect_form_validate() works fine and gives me a lot of data from my client and the transaction.

In my sandbox seller account I can see the payment is accepted and I earned my bucks ;)

Here the problems:

The orders overview at admin/commerce/orders only shows pending orders instead completed although the posted data from paypal show

[payment_status] => Completed

Next when I go to the payment of any order I see that there's no payment method available although payment is done per WPS.

admin/commerce/orders/1/payment:

No payment methods available to add payments.

I believe that these are the reasons why my hook I want to use is not called?? I want to change the user role after the transaction is completed so I took hook_commerce_paypal_ipn_process() without success.

Does anybody has any ideas??

My modules: commerce 7.x-1.11+52-dev, PayPal 7.x-2.3+4-dev, Commerce (Tax)7.x-1.0-rc2, rules 7.x-2.9

maen

Importing nested XML using Feeds XPath Parser

1 week 1 day 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

1 week 1 day 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()

1 week 1 day 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?

1 week 1 day 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

1 week 1 day 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
Checked
9 hours 6 minutes ago
most recent 30 from drupal.stackexchange.com
Subscribe to Drupal StackExchange feed