workflowHasData example

/** * Builds the form to delete Workflow entities. * * @internal */
class WorkflowDeleteForm extends EntityConfirmFormBase {

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    if ($this->entity->getTypePlugin()->workflowHasData($this->entity)) {
      $form['#title'] = $this->getQuestion();
      $form['description'] = ['#markup' => $this->t('This workflow is in use. You cannot remove this workflow until you have removed all content using it.')];
      return $form;
    }

    return parent::buildForm($form$form_state);
  }

  /** * {@inheritdoc} */
  
->getTargetStorage()
              ->read($unprocessed_configuration);
            $diff = array_diff_key($workflow_config['type_settings']['states']$original_workflow_config['type_settings']['states']);
            foreach (array_keys($diff) as $state_id) {
              $state = $workflow->getTypePlugin()->getState($state_id);
              if ($workflow->getTypePlugin()->workflowStateHasData($workflow$state)) {
                $event->getConfigImporter()->logError($this->t('The moderation state @state_label is being used, but is not in the source storage.', ['@state_label' => $state->label()]));
              }
            }
          }
          if ($op === 'delete') {
            if ($workflow->getTypePlugin()->workflowHasData($workflow)) {
              $event->getConfigImporter()->logError($this->t('The workflow @workflow_label is being used, and cannot be deleted.', ['@workflow_label' => $workflow->label()]));
            }
          }
        }
      }
    }
  }

  /** * Get the workflow entity object from the configuration name. * * @param string $config_name * The configuration object name. * * @return \Drupal\workflows\WorkflowInterface|null * A workflow entity object. NULL if no matching entity is found. */
Home | Imprint | This part of the site doesn't use cookies.