Last active
July 13, 2020 12:37
-
-
Save rpayanm/96c79483de51d2b1812afbd41b44bbac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 != "") { | |
$entity->field_container_url->title = 'Title'; | |
} | |
} | |
/** | |
* Implements hook_form_alter(). | |
*/ | |
function MODULENAME_form_alter(&$form, FormStateInterface $form_state, $form_id) { | |
// Modificamos el valor del campo boletines para que se guarde. | |
$form['field_X']['widget'][0]['#element_validate'][] = '_MODULENAME_field_X_validate'; | |
$form['field_X']['widget'][0]['value']['#required'] = FALSE; | |
$form['field_X']['#access'] = FALSE; | |
} | |
/** | |
* Callback. | |
*/ | |
function _MODULENAME_field_X_validate(array $element, FormStateInterface $form_state, &$complete_form) { | |
$form_state->setValueForElement($element, ['value' => 'VALUE']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment