Bolt\Storage\ContentRequest\Edit::action PHP Метод

action() публичный Метод

Do the edit form for a record.
public action ( Content $content, Bolt\Storage\Mapping\ContentType $contentType, boolean $duplicate ) : array
$content Bolt\Storage\Entity\Content A content record
$contentType Bolt\Storage\Mapping\ContentType The contenttype data
$duplicate boolean If TRUE create a duplicate record
Результат array
    public function action(Content $content, ContentType $contentType, $duplicate)
    {
        $contentTypeSlug = $contentType['slug'];
        $new = $content->getId() === null ?: false;
        $oldStatus = $content->getStatus();
        $allStatuses = ['published', 'held', 'draft', 'timed'];
        $allowedStatuses = [];
        foreach ($allStatuses as $status) {
            if ($this->users->isContentStatusTransitionAllowed($oldStatus, $status, $contentTypeSlug, $content->getId())) {
                $allowedStatuses[] = $status;
            }
        }
        // For duplicating a record, clear base field values.
        if ($duplicate) {
            $content->setId('');
            $content->setSlug('');
            $content->setDatecreated('');
            $content->setDatepublish('');
            $content->setDatedepublish(null);
            $content->setDatechanged('');
            $content->setUsername('');
            $content->setOwnerid('');
            $this->loggerFlash->info(Trans::__('contenttypes.generic.duplicated-finalize', ['%contenttype%' => $contentTypeSlug]));
        }
        // Set the users and the current owner of this content.
        if ($new || $duplicate) {
            // For brand-new and duplicated items, the creator becomes the owner.
            $contentowner = $this->users->getCurrentUser();
        } else {
            // For existing items, we'll just keep the current owner.
            $contentowner = $this->users->getUser($content->getOwnerid());
        }
        // Build list of incoming non inverted related records.
        $incomingNotInverted = [];
        foreach ($content->getRelation()->incoming($content) as $relation) {
            if ($relation->isInverted()) {
                continue;
            }
            $fromContentType = $relation->getFromContenttype();
            $record = $this->em->getContent($fromContentType . '/' . $relation->getFromId());
            if ($record) {
                $incomingNotInverted[$fromContentType][] = $record;
            }
        }
        $templateFieldsData = [];
        if (($templateFields = $content->getTemplatefields()) && $templateFields instanceof TemplateFields) {
            $templateFieldsData = $templateFields->getContenttype()->getFields();
        }
        // Build context for Twig.
        $contextCan = ['upload' => $this->users->isAllowed('files:uploads'), 'publish' => $this->users->isAllowed('contenttype:' . $contentTypeSlug . ':publish:' . $content->getId()), 'depublish' => $this->users->isAllowed('contenttype:' . $contentTypeSlug . ':depublish:' . $content->getId()), 'change_ownership' => $this->users->isAllowed('contenttype:' . $contentTypeSlug . ':change-ownership:' . $content->getId())];
        $contextHas = ['incoming_relations' => count($incomingNotInverted) > 0, 'relations' => isset($contentType['relations']), 'tabs' => $contentType['groups'] !== [], 'taxonomy' => isset($contentType['taxonomy']), 'templatefields' => count($templateFieldsData) > 0];
        $contextValues = ['datepublish' => $this->getPublishingDate($content->getDatepublish(), true), 'datedepublish' => $this->getPublishingDate($content->getDatedepublish())];
        $context = ['incoming_not_inv' => $incomingNotInverted, 'contenttype' => $contentType, 'content' => $content, 'allowed_status' => $allowedStatuses, 'contentowner' => $contentowner, 'fields' => $this->config->fields->fields(), 'fieldtemplates' => $this->getTemplateFieldTemplates($contentType, $content), 'fieldtypes' => $this->getUsedFieldtypes($contentType, $content, $contextHas), 'groups' => $this->createGroupTabs($contentType, $contextHas), 'can' => $contextCan, 'has' => $contextHas, 'values' => $contextValues, 'relations_list' => $this->getRelationsList($contentType)];
        return $context;
    }