Skip to content
Snippets Groups Projects
Commit cc744c7e authored by Marcus Johansson's avatar Marcus Johansson Committed by Marcus Johansson
Browse files

Issue #3416190 by Marcus_Johansson: Duplication of configuration items for status on config-imort

parent 2f703d26
Branches
Tags 1.0.0-beta1
No related merge requests found
Pipeline #80670 passed
......@@ -36,7 +36,8 @@ function ai_interpolator_entity_presave(EntityInterface $entity) {
* Implements hook_entity_insert().
*/
function ai_interpolator_entity_insert(EntityInterface $entity) {
if ($entity instanceof FieldConfig) {
// Never generate on import since that will be done via the importer.
if ($entity instanceof FieldConfig && _ai_interpolator_can_import_toggle()) {
\Drupal::service('ai_interpolator.status_field')->modifyStatusField($entity->get('entity_type'), $entity->get('bundle'));
}
if (_ai_interpolator_entity_can_save_toggle()) {
......@@ -48,7 +49,7 @@ function ai_interpolator_entity_insert(EntityInterface $entity) {
* Implements hook_entity_update().
*/
function ai_interpolator_entity_update(EntityInterface $entity) {
if ($entity instanceof FieldConfig) {
if ($entity instanceof FieldConfig && _ai_interpolator_can_import_toggle()) {
\Drupal::service('ai_interpolator.status_field')->modifyStatusField($entity->get('entity_type'), $entity->get('bundle'));
}
if (_ai_interpolator_entity_can_save_toggle()) {
......@@ -60,11 +61,20 @@ function ai_interpolator_entity_update(EntityInterface $entity) {
* Implements hook_entity_delete().
*/
function ai_interpolator_entity_delete(EntityInterface $entity) {
if ($entity instanceof FieldConfig && _ai_interpolator_entity_can_save_toggle()) {
if ($entity instanceof FieldConfig && _ai_interpolator_entity_can_save_toggle() && _ai_interpolator_can_import_toggle()) {
\Drupal::service('ai_interpolator.status_field')->modifyStatusField($entity->get('entity_type'), $entity->get('bundle'));
}
}
/**
* Implements hook_entity_insert().
*/
function ai_interpolator_config_import_steps_alter(&$context) {
// We disable generation from entities while importing, so we don't have a
// mis-match of configurations.
_ai_interpolator_can_import_toggle(FALSE);
}
/**
* Global function to toggle or check if to save.
*
......@@ -84,3 +94,23 @@ function _ai_interpolator_entity_can_save_toggle($newToggle = NULL) {
}
return $toggle;
}
/**
* Global function to toggle if import is possible.
*
* @param bool $newToggle
* The new toggle if you want to change it.
*
* @return bool
* If it is possible to import or not.
*/
function _ai_interpolator_can_import_toggle($newToggle = NULL) {
static $toggle;
// Set default to TRUE.
// @codingStandardsIgnoreLine
$toggle = $toggle === NULL ? TRUE : $toggle;
if (isset($newToggle)) {
$toggle = $newToggle;
}
return $toggle;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment