workflowStateHasData example

$original_workflow_config = $event->getConfigImporter()
              ->getStorageComparer()
              ->getSourceStorage()
              ->read($unprocessed_configuration);
            $workflow_config = $event->getConfigImporter()
              ->getStorageComparer()
              ->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()]));
            }
          }
        }
      }
    }

  public function buildForm(array $form, FormStateInterface $form_state, WorkflowInterface $workflow = NULL, $workflow_state = NULL) {
    if (!$workflow->getTypePlugin()->hasState($workflow_state)) {
      throw new NotFoundHttpException();
    }
    $this->workflow = $workflow;
    $this->stateId = $workflow_state;

    if ($this->workflow->getTypePlugin()->workflowStateHasData($this->workflow, $this->workflow->getTypePlugin()->getState($this->stateId))) {
      $form['#title'] = $this->getQuestion();
      $form['description'] = ['#markup' => $this->t('This workflow state is in use. You cannot remove this workflow state until you have removed all content using it.')];
      return $form;
    }

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

  /** * {@inheritdoc} */
  
Home | Imprint | This part of the site doesn't use cookies.