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

Attach multiple files programmatically in Drupal 8: foreach ($fileIds as $fid) { $node->field_images[] = [ 'target_id' => $fid, 'alt' => 'ALT TEXT', 'title' => 'TITLE TEXT' ]; } $node->save();


0

There is a Relationship that introduces "backwards" Entity reference info into the Views. In Drupal 7 that is called something like this (you can find this in the list of Relationships in your Content Views under the Entity Reference Category): Entity Reference: Referencing entity A bridge to the User entity that is referencing Content via field_[...


0

I have also encountered the same error. Even if I export using UTF-8 charset the problem was there. The problem was with HeidiSQL (version 8.3) for me. When I imported it using mysql command everything started working fine.


0

It turns out that the Commerce Addressbook Extra module takes care of this. In case anyone else is searching after a smooth solution. Link to module


0

Could you use "tabledrag", the code draggableviews uses to do dragging? It is basically javascript acting on an html table, with a weights column to remember the order. Have a look at how the block module uses it (but bear in mind block is more complex because it has multiple regions to manage). For tabledrag to work you need your questions in the form of ...


1

Drupal 6 If your array contains strings you need to tell db_placeholders() $colours = array('red', 'yellow', 'blue'); $placeholders = db_placeholders($colours,'text'); $result = db_query("SELECT * FROM {bricks} WHERE colour IN ($placeholders)", $colours);


0

With Stef help, I figured it out for D7 /** * Implements hook_form_alter(). */ function MYMODULE_form_alter(&$form, &$form_state, $form_id) if ($form_id == 'MYNODE_node_form') { $item = $form['field_NAME'][LANGUAGE_NONE][0]; // Add a minimum of 5 fields. for ($n=1; $n<5; $n++) { if(!isset($form['field_NAME'][LANGUAGE_NONE][$n])...


0

Have tested this in Drupal 8 but I think it is the same for drupal 7. if($form_id == 'node_MYCONTENTTYPE_form') { $item = $form['FIELD_MY_FIELD_NAME']['widget'][0]; for ($n=1; $n<5; $n++) { if(!isset($form['FIELD_MY_FIELD_NAME']['widget'][$n])) { $form['FIELD_MY_FIELD_NAME']['widget'][$n] = $item; } } }


1

The XML Sitemap module doesn't rebuild sitemaps on every node save/load; also, it's not cached like other artifacts in Drupal. The module tracks XML Sitemap links and they are added/removed upon cron runs. So you'll need to run cron to rebuild your sitemap files. You can also follow some of the steps in the Setting up your site map (7.x) documentation: ...


0

I have found the solution. You need to add these 3 lines of code to the page where the link <a href="/my_module/nojs/test-page" class="ctools-use-modal">Open modal</a> is displaying. ctools_include('ajax'); ctools_include('modal'); ctools_modal_add_js();


0

I suspect, though am not sure, that the render sidebar_first in the footer is not rendering because it has already been rendered. In D7, try putting a call to: "unhide($page['sidebar_first'])" immediately before the footer call to render()


0

I was able to disable use of the CDN in Drupal Bootstrap 7.x-3.25 in a subtheme we can call subtheme_name. First I loaded the site with the CDN enabled, and then went into the browser developer tools, looked at the network tab, reloaded the page, then copied the URLs for bootstrap.css, drupal-bootstrap.css and bootstrap.js. I then downloaded those files ...


0

Drupal looks for modules in the following directories inside the Drupal root directory. (The directories are listed in the order they are used when looking for modules.) modules profiles/$profile/modules sites/all/modules $conf/modules $profile is the name of the profile used for the installation; $conf is the directory containing the settings.php file ...


0

Well yes you can ... but you shouldn't you may want to think of the code quality of the custom module, because it should only be responsible for the exact functionality you require. I say you can because yes: //Enable. $modules = ['custom_scarry_module']; module_enable($modules, TRUE); // Disable. if (module_exists('custom_scarry_module')) { ...


1

I put a breakpoint on one script's attach behaviours and inspected the call stack both times it was called. The first time was expected, from drupal.js, and the second turned out to be from a call in the EU Cookie Compliance module. This turned out to be a bug in the EU Cookie Compliance module. Thanks for comments. I'll leave this here in case anyone else ...


0

For Drupal 8, to delete a field from an entity: $entity = Node::load($nid); unset($entity->field_name); This will call the magic method __unset() from ContentEntityBase: public function __unset($name) { // Unsetting a field means emptying it. if ($this->hasField($name)) { $this->get($name)->setValue([]); } // For non-...


1

This should work. Drush bootstraps Drupal before discovering module commands, so the first step is to make sure your commands are defined in a drush.services.yml file as usual. From there, you should be able to define dynamic options using hook options. Since Drush bootstraps Drupal prior to discovering module commands, you should find that the Drupal site ...


0

Sorry... wrote this script for Drupal 8 remote machines with aliases; easily adaptable to local if necessary. if [ $# -lt 1 ] then echo "Usage : $0 sitealias [all/disabled/enabled] [rolename]" echo "Note: this only runs on Drupal 8 schema" exit fi ARG1=$1 ARG2=${2:-all} ARG3=${3:-nothing} if [ "$ARG3" != "nothing" ] then ...


0

Before we start, we must be aware of the fact that there are few tables of Drupal, which gets updated when an anonymous user makes request to Drupal 7: The list goes below, on analysis, which requires more than SELECT privileges for an Anonymous user: cache, cache_*, watchdog, semaphore, flood, sessions Any Other depending on Contrib Modules you use, like ...


0

I'm not sure, based on your code, how you are adding buttons to your form(s)/pages, however, I would venture to guess the AJAX controlled buttons are not working because they are calling the built-in loading/submit callbacks within the Drupal 7 AJAX API (example.) You may find the following example useful: /** * Implementation of hook_menu(). */ function ...


0

yourwebsite.com/user - this is the standard Drupal login URL (at least for 7) and bots find it routinely. Remove visitor registration as described in Chapabu's answer


1

D7, install Conditional rules module, this module let's you add aditional conditions at action section in rules UI. You say your event is 'checkout proccess', so, the first thing you need is to load your 'pizza' node object in to rules, I am assuming that you have a field in your product-fields referencing to your 'pizza-content-type'. To do this, in ...


2

For simple displaying of taxonomy term Assuming your are using entityreference for Drupal 7 the module provides out of the box a field formatter that allows you to display the Rendered entity with a specific view mode Thus you can display the referenced entity with the taxonomy term included. Go to the manage display of your Content B and change the ...


1

https://www.drupal.org/project/backup_migrate/issues/3037038 Update April 10: Workaround Per e5sego, the "nodesquirrel_default_endpoint_urls" variable can be changed to "74.121.199.90/services/xmlrpc" to avoid the current DNS problems we're seeing, e.g. drush vset nodesquirrel_default_endpoint_urls "74.121.199.90/services/xmlrpc" Just make sure ...


1

In the Twig documentation, there is an entry that can help you out: https://twig.symfony.com/doc/2.x/filters/nl2br.html {{ "I like Twig.\nYou will like it too."|nl2br }} will output: I like Twig.<br /> You will like it too. So inside a string, you could use \n or the function nl2br at the end of it.


2

You can add external databases in your settings.php file: $databases['external']['default']= array( 'database'=>'', 'username'=>'', 'password'=>'', 'prefix'=>'', 'host'=>'', 'port'=>'3306', 'namespace'=>'Drupal\\Core\\Database\\Driver\\mysql', 'driver'=>'mysql', ); Then, in a custom module you can query for nodes, ...


0

A hook is available for this that is: Implements hook_print_pdf_filename_alter /** * Implements hook_print_pdf_filename_alter(). */ function MY_MODULE_print_pdf_filename_alter(&$pdf_filename, &$path) { $pdf_filename = htmlspecialchars_decode($pdf_filename, ENT_NOQUOTES); }


0

Yes. safe_value is derived from value; safe_value contains the results of _text_sanitize() after it applies all the filters you've set on your text field. It isn't set after a node save; it's set on a field load; the field module loads it via hook_field_load() with its text_field_load() invocation.


0

You can remove it using hook_html_head_alter like the following: /** * Implements hook_html_head_alter(). */ function myTheme_html_head_alter(&$head_elements) { foreach ($head_elements as $key => $head_element) { if (strpos($key, 'drupal_add_html_head_link:shortlink') === 0) { unset($head_elements[$key]); } } } PS : the above ...


0

Maybe it can help. // Row object containing the specific item just imported. $row = $event->getRow(); if (!$row->needsUpdate()) { return; }


1

It's user input and should be considered unsafe; you should always sanitise it. For the specific example you've given where it isn't, the title is already sanitised before it's passed to the theme function containing the t() call. This happens in field_multiple_value_form() $title = check_plain($instance['label']); ... $element = array( ... '#title' =...


0

The correct way is to check with check_plain() to prevent cross site scripting attacks in the first example from modules/field/field.form.inc $element['#title'] passed as arg to t function. if you look at t function source code it call format_string function it check plain $args[$key] = check_plain($value);.


0

I have managed to fix this issue by reverting the module to an older version.As I see in the release notes Issue #3037177 by itcrowd72, omrmankar, troybthompson: PHP 7.2 each() function is deprecated The php version I am still using is 5.6. It looks like the new module version is not ok with 5.6, or at least with my setup.


0

Chiming in late here, but I came across this yesterday after having the same problem. In my case, there was a stray call to dpm() in hook_preprocess_field_collection_item(); The Devel module was disabled in production, so when the page hit the dpm() call, everything broke. I don't know why this caused the page to go into maintenance mode, but removing the ...


0

It looks like you haven't installed the plugin. Just run: composer require drupal-composer/preserve-paths And try again. If it still doesn't work, you'll probably need to report it as a bug to the plugin's issue queue.


0

JFR in this article an other flexible pattern-based solution is offered in a form of raw SQL-query, but was not working for me as good as Mohammad's: https://thebarton.org/clear-drupal-cache-sql-query/


0

Try to delete the includes folder and add new includes folder from 7.66 version, bootstrap.inc defines the drupal version.


1

First add the Media RSS namespace to your views-view-rss.tpl.php <rss version="2.0" xml:base="<?php print $link; ?>"<?php print $namespaces; ?> xmlns:media="http://search.yahoo.com/mrss/"> Then add the tag to your views-view-row-rss.tpl.php <media:content url="<?php print image_style_url('my_img_style_id', $node->field_image['...


1

Compatible with PHP 7.2? Yes, currently the only issue I see in the issue queue is: PHP 7.2 Warning: A non-numeric value encountered in commerce_currency_amount_to_decimal() You'll have to apply this patch yourself since it has not been committed.


0

This is my html.tpl.php <?php global $base_url, $theme_path ?> <!DOCTYPE html> <html class="no-js" lang="<?= $language->language ?>" dir="<?= $language->dir ?>"<?= $rdf_namespaces, !empty($schemaorg) ? $schemaorg : ''; ?>> <head> <?= $head; ?> <!-- Set the viewport width to device ...


0

if you want to use AMP for specific pages, you might want to take a look at the AMP module. But if you still want to add the amp attribut to the <HTML> tag manually, here's one way: Overwrite the html.tpl.php template by copying the original tpl file (modules/system/html.tpl.php) to your current theme (sites/all/themes/your_theme/). Then add the ...


1

I am not a specialist of dompdf, but having used fpdf, I think it's something you do in your print template or custom module that converts the fields in dompdf format. You may need to set a php rule like this: $title = mb_convert_encoding($title, 'HTML-ENTITIES', 'UTF-8'); Source: https://stackoverflow.com/questions/16384517/dompdf-character-encoding-utf-...


0

Yes you can use PHP within some custom rule, and then include your SQL statements. But that requires PHP code to be stored in your Drupal database ... which is bad (repeat: bad). I recommend you to not go that path. But instead you should use the Message module, to create the equivalent of those database records you want to create. Have a look at my answer ...


1

Checkout the Habitat module. It allows you to set modules that should be enable or disabled on the different environments you have. You can set this in settings.php. I use a settings.php that loads an environment specific settings.php and in these I have the habitat setting for each environment.


0

Instead of creating a security breach in your site (logged in user is not bullet proof and relies maybe a bit too much on trust of user's sense of responsability considering keeping strong password and clean browsers, closing sessions...), I would suggest to look into the existing statistics module and match the objective by configuration and customisation. ...


1

You can use pathauto module. After installing the pathauto module, please configure the path of article content type from here admin/config/search/path/patterns. Note: To use pattern require token module. Then use like following pattern: categories/[node:field-token-of-term-reference-field]/[node:title]


0

Try using template_preprocess_views_view_fields If you still can't access that field there then: Ditch views_view_field Add a "custom text field" (their field_name will be nothing). In template_preprocess_views_view_fields programmatically add view to this "custom text field". /sites/all/themes/THEMENAME/template.php function ...


Top 50 recent answers are included