$host = Drupal::request()->getSchemeAndHttpHost() . Drupal::request()->getBasePath();
echo $host;
El resultado:
Con base url https://www.example.com/subsite y la página https://www.example.com/subsite/news sería:
https://www.example.com/subsite
// dependencies: | |
// - core/jquery | |
// - core/drupal | |
// - core/once | |
// https://www.drupal.org/docs/drupal-apis/javascript-api/javascript-api-overview | |
(function ($, Drupal, once) { | |
'use strict'; | |
Drupal.behaviors.myCustomBehavior = { |
https://symfony.com/doc/current/setup.html#creating-symfony-applications |
$host = Drupal::request()->getSchemeAndHttpHost() . Drupal::request()->getBasePath();
echo $host;
El resultado:
Con base url https://www.example.com/subsite y la página https://www.example.com/subsite/news sería:
https://www.example.com/subsite
.parent { | |
gap: 20px; | |
.each-item { | |
@supports (-webkit-touch-callout: none) and (not (translate: none)) { | |
margin-top: 20px; | |
margin-right: 20px | |
} | |
} | |
// on desktop |
Allow other domain do Rest request to drupal site: | |
- Use `services.yml`: | |
``` | |
cors.config: | |
enabled: true | |
# Specify allowed headers, like 'x-allowed-header'. | |
allowedHeaders: ['*'] # All header | |
# Specify allowed request methods, specify ['*'] to allow all possible ones. | |
allowedMethods: ['GET'] # Methods |
The friendly.libraries.yml file will look like this:
friendly-greeting:
version: 1.0
license: GPL
js:
js/friendly-greeting.js: { }
dependencies:
- core/drupalSettings
See https://blog.acromedia.com/making-drupal-code-standards-work-for-you-with-phpstorm-phpcs-phpcbf
<?php | |
/** | |
* Implements hook_module_implements_alter(). | |
*/ | |
function YOURMODULENAME_module_implements_alter(&$implementations, $hook) { | |
// I want that my hook_form_alter will execute last | |
// Move our hook_form_alter() implementation to the end of the list. | |
$my_module = 'MYMODULENAME'; | |
if ($hook == 'form_alter') { |
<?php | |
// Podemos hacerlo en el hook_entity_presave(), ejemplo en un block. | |
/** | |
* Implements hook_entity_presave(). | |
*/ | |
function MODULO_NAME_block_content_presave(BlockContent $entity) { | |
$value_title = $entity->field_container_url->title; | |
if ($value_title != "") { |
<?php | |
/** | |
* Implements hook_field_widget_multivalue_form_alter(). | |
*/ | |
function MODULE_NAME_field_widget_multivalue_form_alter(&$elements, FormStateInterface $form_state, $context) { | |
$field = $context['items']->getName(); | |
$build_info = $form_state->getBuildInfo(); | |
if ($field == "FIELD_NAME") { |