Ibexa DXP Discussions

Community discussion forum for developers working with Ibexa DXP

Create URL ValueObject programmatically


I just want to create an eZ\Publish\API\Repository\Values\URL\URL object (Store in ezurl table in DB) in a command.

How to do that?

I’m not near a computer right now, so I can’t give you a piece of working code, but there is an URL service available in the repository as of eZ Platform 2.0 which you can use to create new URLs.

In v1, I don’t think it can be done.

In V1 URLService only expose createUpdateStruct() and updateUrl() functions … (and some find*(), * load*())

So I’ll deal with this problem when I get the exact version of eZ for my project.
(Pro version in contractual terms)



I have my instance ezplatform enterprise edition that works :slight_smile:
But the URLService does not have more features than before …

URLs are ValueObject. There may be a generic service to create a ValueObject?

class URL extends ValueObject

This is the wrong solution.

    try {
        return $this->repository->getURLService()->loadByUrl($url);
    } catch (NotFoundException $e) {
        try {
            /** @var \Doctrine\DBAL\Connection $connection */
            $connection = $this->container->get('database_connection');
            $connection->exec("INSERT INTO ezurl (url) VALUES ('$url'); ");
            $urlObject = $this->repository->getURLService()->loadByUrl($url);
            $struct = $this->repository->getURLService()->createUpdateStruct();
            $struct->url = $url;
            $urlObject = $this->repository->getURLService()->updateUrl($urlObject, $struct);
        } catch (\Exception $e) {
            throw $e;
    return $urlObject;