Add or update a PageMeta entity, and return it for save

@param Page $page
@param string $metaName
@param string $metaValue
@return \Fulgurio\LightCMSBundle\Entity\PageMeta
510967
final public function initMetaEntity(Page $page, $metaName, $metaValue)
    {
        $this->initPageMetas($page);
        if (isset($this->pageMetas[$metaName]))
        {
            $entity = $this->pageMetas[$metaName];
        }
        else
        {
            $entity = new PageMeta();
            $entity->setPage($page);
            $entity->setMetaKey($metaName);
        }
        $entity->setMetaValue($metaValue);
        return $entity;
    }
1288070
public function transform(Metadata $meta, $entity)
    {
        $this->validateConfiguration($meta, $entity, 'show');

        $this->eventDispatcher->dispatch(Events::PRE_SHOW_VIEW_CREATING, new ShowViewEvent($entity));

        $view = new ShowView();

        $configuration = $meta->getConfiguration();
        $translationPrefix = $meta->getEntityTranslationPrefix();

        foreach ($configuration['view']['show']['fields'] as $field => $attr) {
            if ($this->fieldBlacklistManager->isFieldBlacklisted($meta, $field, '[view][show]')
                || $this->isFieldContentHidden($attr, $entity)
            ) {
                continue;
            }

            $label = $translationPrefix.StringsUtil::toUnderscore($field);

            $content = $this->getFieldContent($entity, $field, $attr, $meta->getMappings());

            $view->addItem(new Item($label, $content));
        }

        return $view;
    }
1266221
private function setMetatags($page) {
        if(isset($page->description)) {
            Yii::$app->view->registerMetaTag([
                'name' => 'description',
                'content' => $page->description
            ]);
        }
        if(isset($page->keywords)) {
            Yii::$app->view->registerMetaTag([
                'name' => 'keywords',
                'content' => $page->keywords
            ]);
        }
    }
360082
public function update(PageRequest $request, Page $page)
    {
        try {
            $attributes = $request->all();

            $page->update($attributes);
            return $this->response->message(trans('messages.success.updated', ['Module' => trans('page::page.name')]))
                ->code(204)
                ->status('success')
                ->url(guard_url('page/page/' . $page->getRouteKey()))
                ->redirect();
        } catch (Exception $e) {
            return $this->response->message($e->getMessage())
                ->code(400)
                ->status('error')
                ->url(guard_url('page/page/' . $page->getRouteKey()))
                ->redirect();
        }

    }
676424
public function setPage(\Fulgurio\LightCMSBundle\Entity\Page $page = null)
    {
        $this->page = $page;

        return $this;
    }
48735
public function add(Request $request, Page $page)
    {
        $this->auth($page);

        $name = $request->input('tag');
        $group = $request->input('group');

        $tag = TagFacade::findOrCreate($name, $group);

        $page->addTag($tag);

        Event::fire(new PageHadTagAdded($page, $tag));

        return $tag->getId();
    }
215662
public function assertCanUpdateSitePage(
        \Rcm\Entity\Page $page
    ) {
        $pageId = $page->getPageId();
        $pageName = $page->getName();
        $pageType = $page->getPageType();
        $site = $page->getSite();

        $allowDuplicates = $this->allowDuplicates($pageType);

        if ($allowDuplicates) {
            return;
        }

        $pageExists = $this->duplicateSitePageExist($page);

        if (!$pageExists) {
            return;
        }

        throw new PageException(
            "Cannot update page: ({$pageId}). " .
            "Duplicate page names not allowed for name: ({$pageName}) type: ({$pageType}) siteId: " .
            '(' . $site->getSiteId() . ')'
        );
    }
1340754
public function addMeta($key, $value)
    {
        $meta = call_user_func_array("{$this->metaModel}::firstOrNew", [['key' => $key, $this->getMetaForeignKey() => $this->getKey()]]);
        $meta->value = $value;

        return $this->meta()->save($meta);
    }
10785
public function createPage(
        SiteEntity $site,
        $pageData,
        $publishPage = false,
        $doFlush = true
    ) {
        if (empty($pageData['createdByUserId'])) {
            throw new PageException('CreatedByUserId is required to create a page.');
        }
        if (empty($pageData['createdReason'])) {
            $pageData['createdReason'] = Tracking::UNKNOWN_REASON;
        }
        if (empty($pageData['author'])) {
            throw new PageException('Author is required to create a page.');
        }
        $revision = new Revision(
            $pageData['createdByUserId'],
            $pageData['createdReason']
        );
        $revision->setAuthor($pageData['author']);

        // we should not have an Id on page create
        unset($pageData['pageId']);

        $page = new PageEntity(
            $pageData['createdByUserId'],
            $pageData['createdReason']
        );
        $page->populate($pageData);

        $page->setSite($site);

        $this->assertCanCreateSitePage(
            $page->getSite(),
            $page->getName(),
            $page->getPageType()
        );

        if (!$publishPage) {
            $page->setStagedRevision($revision);
        } else {
            $page->setPublishedRevision($revision);
        }

        $page->addRevision($revision);

        $this->_em->persist($revision);
        $this->_em->persist($page);

        if ($doFlush) {
            $this->_em->flush(
                [
                    $revision,
                    $page
                ]
            );
        }

        return $page;
    }
29389
public function addMeta($property, $content, $position)
    {
        $content = $this->_normalizeContent($property, $content);

        switch($property) {
            case self::OG_TITLE:
            case self::OG_TYPE:
            case self::OG_DESCRIPTION:
            case self::OG_LOCALE:
            case self::OG_SITE_NAME:
            case self::OG_URL:
                if($this->hasMeta($property)) {
                    $this->removeMeta($property);
                    //$this->getMeta($property)->setContent($content);
                }
                break;
        }

        if($position == self::APPEND) {
            static::$storage->append(new Meta($property, $content));
        } else {
            $values = static::$storage->getArrayCopy();
            array_unshift($values, new Meta($property, $content));
            static::$storage->exchangeArray($values);
            unset($values);
        }

        return $this;
    }
727859
public function setPage(\VFou\CmsBundle\Entity\Page $page = null)
    {
        $this->page = $page;

        return $this;
    }
1188238
public static function fromEntity(FieldMetadata $meta, $entity) {
        $instance = new static($meta, $entity->getAttribute($meta->name));

        return $instance;
    }
45349
public function update(Page $page)
    {
        $attributes = request()->validate(Page::$rules, Page::$messages);

        $attributes['is_header'] = boolval(input('is_header'));
        $attributes['is_hidden'] = boolval(input('is_hidden'));
        $attributes['is_footer'] = boolval(input('is_footer'));
        $attributes['is_featured'] = boolval(input('is_featured'));

        $page = $this->updateEntry($page, $attributes);
        $page->updateUrl()->save();
        $page->banners()->sync(input('banners'));

        return redirect_to_resource();
    }
271167
public function setPage(Page $page)
    {
        $this->_page = $page;
        $page->setMainSection($this);

        return $this;
    }
787413
public function save(ClassMetadata $meta, Component $component, &$entity): bool
    {
        if (is_object($entity)) {
            return false;
        }

        $reflection = $meta->getReflectionClass();
        $constructor = $reflection->getConstructor();

        if ($constructor) {
            $constructorNewParameters = [];

            /** @var Container|null $baseComponent */
            $baseComponent = $component instanceof Container ? $component : $component->getParent();

            if ($baseComponent === null) {
                throw new InvalidStateException(__METHOD__ . ' cannot found container');
            }

            foreach ($constructor->getParameters() as $constructorParameter) {
                // property name
                $name = $constructorParameter->getName();

                /** @var BaseControl|Container|null $child */
                $child = $baseComponent->getComponent($name, false);

                // test if parameter is required and control exists
                if ($child === null && $constructorParameter->isOptional() === false) {
                    throw new InvalidStateException("Can't create new instance: control '$name' is missing");
                }

                if ($child === null) {
                    continue;
                }

                if ($meta->hasAssociation($name) === false) {
                    if ($child instanceof Container) {
                        throw new InvalidStateException('Scalar type and form container? What is wrong with you?');
                    }
                    // scalar type
                    $constructorNewParameters[$name] = $child->getValue();
                    continue;
                }

                // object type
                $targetClass = $meta->getAssociationTargetClass($name);

                if ($child instanceof Container) {
                    // probably OneToOne Container
                    $this->save($this->entityManager->getClassMetadata($targetClass), $child, $targetClass);
                    // $targetClass is new instance
                    $constructorNewParameters[$name] = $targetClass;
                } elseif ($child instanceof BaseControl) {
                    $constructorNewParameters[$name] = $this->entityManager->find($targetClass, $child->getValue());
                }
            }

            $entity = $reflection->newInstanceArgs($constructorNewParameters);
        } else {
            $entity = $reflection->newInstanceWithoutConstructor();
        }

        return false;
    }
113861
public function storeMeta($metaData, $metaType, $metaId, $metaModel = Meta::class)
    {
        // Validation required instead of type hinting because it could be passed as false or NULL
        if (!is_array($metaData)) {
            return;
        }

        foreach ($metaData as $key => $value) {
            $modelInstance = call_user_func(
                [$metaModel, 'firstOrNew'],
                [
                    'key'       => $key,
                    'meta_type' => $metaType,
                    'meta_id'   => $metaId,
                ]
            );

            $value = $this->removeEmptyValues($value);
            if (!empty($value)) {
                $modelInstance->setAttribute('value', $value);
                $modelInstance->save();
                continue;
            }

            // The value is empty, remove the row
            if ($modelInstance->exists) {
                $modelInstance->delete();
            }
        }
    }
777909
public function setMeta($metaEntities)
    {
        $currentMeta = $this->entity->getMeta();
        foreach ($metaEntities as $singleMeta) {
            $metaEntity = $this->getSingleMetaById($currentMeta, $singleMeta->getId());
            if (!$metaEntity) {
                $metaEntity = $singleMeta;
                $this->entity->addMeta($metaEntity);
            }

            $metaEntity->setCategory($this->entity);
            $metaEntity->setKey($singleMeta->getKey());
            $metaEntity->setValue($singleMeta->getValue());
            $metaEntity->setLocale($singleMeta->getLocale());
        }

        return $this;
    }