Pimcore\WorkflowManagement\Workflow\Config::getElementWorkflowConfig PHP Метод

getElementWorkflowConfig() публичный статический Метод

gets workflow config for element. always returns first valid workflow config
public static getElementWorkflowConfig ( AbstractElement $element ) : array
$element Pimcore\Model\Element\AbstractElement
Результат array
    public static function getElementWorkflowConfig(AbstractElement $element)
    {
        $config = self::getWorkflowManagementConfig();
        if (!is_array($config)) {
            return null;
        }
        $elementType = Service::getElementType($element);
        $elementSubType = $element->getType();
        foreach ($config['workflows'] as $workflow) {
            //workflow is not enabled, continue with next
            if (isset($workflow['enabled']) && !$workflow['enabled']) {
                continue;
            }
            if (isset($workflow['workflowSubject']) && in_array($elementType, $workflow['workflowSubject']['types'])) {
                switch ($elementType) {
                    case 'asset':
                        if (isset($workflow['workflowSubject']['assetTypes']) && is_array($workflow['workflowSubject']['assetTypes'])) {
                            if (in_array($elementSubType, $workflow['workflowSubject']['assetTypes'])) {
                                return $workflow;
                            }
                        } else {
                            Logger::warning('WorkflowManagement::getClassWorkflowConfig workflow does not feature a valid array of available asset types');
                        }
                        break;
                    case 'document':
                        if (isset($workflow['workflowSubject']['documentTypes']) && is_array($workflow['workflowSubject']['documentTypes'])) {
                            if (in_array($elementSubType, $workflow['workflowSubject']['documentTypes'])) {
                                return $workflow;
                            }
                        } else {
                            Logger::warning('WorkflowManagement::getClassWorkflowConfig workflow does not feature a valid array of available document types');
                        }
                        break;
                    case 'object':
                        if ($element instanceof ConcreteObject) {
                            if (isset($workflow['workflowSubject']['classes']) && is_array($workflow['workflowSubject']['classes'])) {
                                $classId = $element->getClassId();
                                if (in_array($classId, $workflow['workflowSubject']['classes'])) {
                                    return $workflow;
                                }
                            } else {
                                Logger::warning('WorkflowManagement::getClassWorkflowConfig workflow does not feature a valid array of available class ID\'s');
                            }
                        }
                        break;
                    default:
                        //unknown element type, return null
                        return null;
                }
            }
        }
        return null;
    }

Usage Example

Пример #1
0
 /**
  * Returns whether or not an element has a workflow
  * @param Asset|ConcreteObject|Document $element
  * @return bool
  */
 public static function elementHasWorkflow(AbstractElement $element)
 {
     $config = Workflow\Config::getElementWorkflowConfig($element);
     if (is_array($config)) {
         return true;
     }
     return false;
 }