bundle/Menu/RelationListMenuBuilder.php
public function createRelationListMenu(string $fieldIdentifier, $contentId = null): ItemInterface
    {
        $content = $contentId !== null ?
            $this->loadService->loadContent($contentId) :
            $this->siteInfoHelper->getSiteInfoContent();

        $menu = $this->factory->createItem('root');

        $menu->setAttribute('location-id', $content->mainLocationId);
        $menu->setExtra('ezlocation', $content->mainLocation);

        if (!$content->hasField($fieldIdentifier)) {
            return $menu;
        }

        $field = $content->getField($fieldIdentifier);
        if (!$field->value instanceof RelationListValue || $field->isEmpty()) {
            return $menu;
        }

        foreach ($field->value->destinationLocationIds as $locationId) {
            if (empty($locationId)) {
                $this->logger->error(sprintf('Empty location ID in RelationList field "%s" for content #%s', $fieldIdentifier, $content->id));

                continue;
            }

            try {
                $location = $this->loadService->loadLocation($locationId);
            } catch (Throwable $t) {
                $this->logger->error($t->getMessage());

                continue;
            }

            $menu->addChild(null, ['ezlocation' => $location]);
        }

        return $menu;
    }
public function createRelationListMenu(string $fieldIdentifier, $contentId = null): ItemInterface
    {
        $content = $contentId !== null ?
            $this->loadService->loadContent($contentId) :
            $this->siteInfoHelper->getSiteInfoContent();

        $menu = $this->factory->createItem('root');

        $menu->setAttribute('location-id', $content->mainLocationId);
        $menu->setExtra('ezlocation', $content->mainLocation);

        if (!$content->hasField($fieldIdentifier)) {
            return $menu;
        }

        $field = $content->getField($fieldIdentifier);
        if (!$field->value instanceof RelationListValue || $field->isEmpty()) {
            return $menu;
        }

        foreach ($field->value->destinationLocationIds as $locationId) {
            if (empty($locationId)) {
                $this->logger->error(sprintf('Empty location ID in RelationList field "%s" for content #%s', $fieldIdentifier, $content->id));

                continue;
            }

            try {
                $location = $this->loadService->loadLocation($locationId);
            } catch (Throwable $t) {
                $this->logger->error($t->getMessage());

                continue;
            }

            $menu->addChild(null, ['ezlocation' => $location]);
        }

        return $menu;
    }
public function createRelationListMenu ( string $ fieldIdentifier , $ contentId = null ) : ItemInterface { $ content = $ contentId !== null ? $ this -> loadService -> loadContent ( $ contentId ) : $ this -> siteInfoHelper -> getSiteInfoContent ( ) ; $ menu = $ this -> factory -> createItem ( 'root' ) ; $ menu -> setAttribute ( 'location-id' , $ content -> mainLocationId ) ; $ menu -> setExtra ( 'ezlocation' , $ content -> mainLocation ) ; if ( ! $ content -> hasField ( $ fieldIdentifier ) ) { return $ menu ; } $ field = $ content -> getField ( $ fieldIdentifier ) ; if ( ! $ field -> value instanceof RelationListValue || $ field -> isEmpty ( ) ) { return $ menu ; } foreach ( $ field -> value -> destinationLocationIds as $ locationId ) { if ( empty ( $ locationId ) ) { $ this -> logger -> error ( sprintf ( 'Empty location ID in RelationList field "%s" for content #%s' , $ fieldIdentifier , $ content -> id ) ) ; continue ; } try { $ location = $ this -> loadService -> loadLocation ( $ locationId ) ; } catch ( Throwable $ t ) { $ this -> logger -> error ( $ t -> getMessage ( ) ) ; continue ; } $ menu -> addChild ( null , [ 'ezlocation' => $ location ] ) ; } return $ menu ; }
Creates the KNP menu from provided content and field identifier.

@param mixed|null $contentId
Creates the KNP menu from provided content and field identifier .