public static function fromMetadata(string $metadata): ? array
    {
        $values = [];
        $splittedParts = explode('~~', $metadata);

        foreach ($splittedParts as $part) {
            $parts = explode('##', $part);
            if (count($parts) > 1) {
                $values[$parts[0]] = $parts[1];
            } else {
                $values[] = $part;
            }
        }

        if (1 == count($values)) {
            $firstAndUniqueElement = reset($values);
            $values = [
                'id' => $firstAndUniqueElement,
                'name' => $firstAndUniqueElement,
            ];
        }

        if (!array_key_exists('id', $values)) {
            return null;
        }

        return $values;
    }
public static function fromMetadata(string $metadata): ? array
    {
        $values = [];
        $splittedParts = explode('~~', $metadata);

        foreach ($splittedParts as $part) {
            $parts = explode('##', $part);
            if (count($parts) > 1) {
                $values[$parts[0]] = $parts[1];
            } else {
                $values[] = $part;
            }
        }

        if (1 == count($values)) {
            $firstAndUniqueElement = reset($values);
            $values = [
                'id' => $firstAndUniqueElement,
                'name' => $firstAndUniqueElement,
            ];
        }

        if (!array_key_exists('id', $values)) {
            return null;
        }

        return $values;
    }
public static function fromMetadata ( string $ metadata ) : ? array { $ values = [ ] ; $ splittedParts = explode ( '~~' , $ metadata ) ; foreach ( $ splittedParts as $ part ) { $ parts = explode ( '##' , $ part ) ; if ( count ( $ parts ) > 1 ) { $ values [ $ parts [ 0 ] ] = $ parts [ 1 ] ; } else { $ values [ ] = $ part ; } } if ( 1 == count ( $ values ) ) { $ firstAndUniqueElement = reset ( $ values ) ; $ values = [ 'id' => $ firstAndUniqueElement , 'name' => $ firstAndUniqueElement , ] ; } if ( ! array_key_exists ( 'id' , $ values ) ) { return null ; } return $ values ; }
metadata format to array.

Allowed these formats

"simpletext"
"id##1234~~name##Marc

First format should cover both id and name with the desired value.

@param string $metadata

@return array|null
metadata format to array .