Change None Text in Select List: $form $form
Change None Text in Select List: $form $form
if (isset($form['field_hero_bg']['widget']['#options']['_none'])) {
$form['field_hero_bg']['widget']['#options']['_none'] = t('Default background
color');
}
$entity->get('field_name')->getValue();
Single value
$entity->get('field_name')->value;
$bgimage_mid = $field_hero_bgimage[0]['target_id'];
Entity reference
Get all referenced entities
$node->get('field_FIELDNAME')->referencedEntities();
After clicking Open Drush Console button on Acquia Dev Desktop, run drush cr command. The console will
display error The filename, directory name, or volume label syntax is incorrect. This is
expected.
Running Drush
From docroot .
php ..\vendor\drush\drush\drush cr
If it's not working, try running drush cr first before running that command.
Drupal console
Running Drupal Console
From docroot .
Composer
Email testing
Tips
Use reroute email module, route all email to an address. Apply this only in some environments by
using Config Split module
Use Papercut SMTP for local testing
Webform
AJAX webform in a modal
TODO
Javascript
Add inline javascript
$form['#attached']['html_head'][] = [
[
'#tag' => 'script',
'#attributes' => [
'type' => 'text/javascript',
],
'#value' => 'function timestamp() {
var response = document.getElementById("g-recaptcha-response");
if (response == null || response.value.trim() == "") {
var elems = JSON.parse(document.getElementsByName("captcha_settings")[0].value);
elems["ts"] = JSON.stringify(new Date().getTime());
document.getElementsByName("captcha_settings")[0].value = JSON.stringify(elems);
}
}
setInterval(timestamp, 500);',
],
'ownerform_snippet',
];
Add drupalSettings
Entity Validation
Reference
https://makedrupaleasy.com/articles/drupal-8-custom-validator-checking-field-depending-value-anoth
er-field
ConfigPages
use Drupal\config_pages\Entity\ConfigPages;
$myConfigPage = ConfigPages::config('my_config_page');
$variables['my_global_value'] = $myConfigPage
->get('field_something')->value;
Patch
Applying patch
Reversing patch
Update Drupal
Reference
https://drupalize.me/tutorial/update-drupals-minor-version?p=3233
$query = $view->query->query();
// Replace arguments.
$arguments = $query->arguments();
if (!empty($arguments) && is_array($arguments)) {
foreach ($arguments as $placeholder => &$value) {
if (is_string($value)) {
$value = "'$value'";
}
}
$string = strtr($string, $arguments);
}
// echo $string;
$out = str_replace(' ', ' ', nl2br($string));