private function setSelectedRelationshipsTo(
        string $sectionHandle,
        string $fieldHandle,
        array $fieldInfo,
        int $id
    ): array {
        /** @var CommonSectionInterface $editing */
        $editing = $this->readSection->read(
            ReadOptions::fromArray([
                ReadOptions::SECTION => $sectionHandle,
                ReadOptions::ID => (int)$id
            ])
        )->current();

        try {
            $method = $this->handleToPropertyName($fieldHandle, $editing::FIELDS);
            $relationshipsEntityMethod = 'get' . ucfirst($method);
            $related = $editing->{$relationshipsEntityMethod}();
            if (!is_null($related)) {
                $relatedIds = [];
                if (is_iterable($related)) {
                    /** @var CommonSectionInterface $relation */
                    foreach ($related as $relation) {
                        $relatedIds[] = $relation->getId();
                    }
                } else {
                    $relatedIds[] = $related->getId();
                }
                foreach ($fieldInfo[$fieldHandle][$fieldInfo[$fieldHandle]['to']] as &$relatable) {
                    if (!empty($relatable['id']) && in_array($relatable['id'], $relatedIds)) {
                        $relatable['selected'] = true;
                    }
                }
            }
        } catch (\Exception $exception) {
            // Empty because we can just return the fieldInfo the way it was if the above fails
        }

        return $fieldInfo;
    }
private function setSelectedRelationshipsTo(
        string $sectionHandle,
        string $fieldHandle,
        array $fieldInfo,
        int $id
    ): array {
        /** @var CommonSectionInterface $editing */
        $editing = $this->readSection->read(
            ReadOptions::fromArray([
                ReadOptions::SECTION => $sectionHandle,
                ReadOptions::ID => (int)$id
            ])
        )->current();

        try {
            $method = $this->handleToPropertyName($fieldHandle, $editing::FIELDS);
            $relationshipsEntityMethod = 'get' . ucfirst($method);
            $related = $editing->{$relationshipsEntityMethod}();
            if (!is_null($related)) {
                $relatedIds = [];
                if (is_iterable($related)) {
                    /** @var CommonSectionInterface $relation */
                    foreach ($related as $relation) {
                        $relatedIds[] = $relation->getId();
                    }
                } else {
                    $relatedIds[] = $related->getId();
                }
                foreach ($fieldInfo[$fieldHandle][$fieldInfo[$fieldHandle]['to']] as &$relatable) {
                    if (!empty($relatable['id']) && in_array($relatable['id'], $relatedIds)) {
                        $relatable['selected'] = true;
                    }
                }
            }
        } catch (\Exception $exception) {
            // Empty because we can just return the fieldInfo the way it was if the above fails
        }

        return $fieldInfo;
    }
private function setSelectedRelationshipsTo ( string $ sectionHandle , string $ fieldHandle , array $ fieldInfo , int $ id ) : array { /** @var CommonSectionInterface $editing */ $ editing = $ this -> readSection -> read ( ReadOptions :: fromArray ( [ ReadOptions :: SECTION => $ sectionHandle , ReadOptions :: ID => ( int ) $ id ] ) ) -> current ( ) ; try { $ method = $ this -> handleToPropertyName ( $ fieldHandle , $ editing :: FIELDS ) ; $ relationshipsEntityMethod = 'get' . ucfirst ( $ method ) ; $ related = $ editing -> { $ relationshipsEntityMethod } ( ) ; if ( ! is_null ( $ related ) ) { $ relatedIds = [ ] ; if ( is_iterable ( $ related ) ) { /** @var CommonSectionInterface $relation */ foreach ( $ related as $ relation ) { $ relatedIds [ ] = $ relation -> getId ( ) ; } } else { $ relatedIds [ ] = $ related -> getId ( ) ; } foreach ( $ fieldInfo [ $ fieldHandle ] [ $ fieldInfo [ $ fieldHandle ] [ 'to' ] ] as & $ relatable ) { if ( ! empty ( $ relatable [ 'id' ] ) && in_array ( $ relatable [ 'id' ] , $ relatedIds ) ) { $ relatable [ 'selected' ] = true ; } } } } catch ( \ Exception $ exception ) { // Empty because we can just return the fieldInfo the way it was if the above fails } return $ fieldInfo ; }
If editing an entry with relationships, mark related as true

@param string $sectionHandle
@param string $fieldHandle
@param array $fieldInfo
@param int $id
@return array
If editing an entry with relationships mark related as true