protected function getMetadata($urlRewrite)
    {

        // initialize the array with the metaddata
        $metadata = array();

        // try to unserialize the metadata from the passed URL rewrite
        if (isset($urlRewrite[MemberNames::METADATA])) {
            $metadata = json_decode($urlRewrite[MemberNames::METADATA], true);
        }

        // query whether or not a category ID has been found
        if (isset($metadata[UrlRewriteObserver::CATEGORY_ID])) {
            // if yes, return the metadata
            return $metadata;
        }

        // if not, append the ID of the root category
        $rootCategory = $this->getRootCategory();
        $metadata[UrlRewriteObserver::CATEGORY_ID] = (integer) $rootCategory[MemberNames::ENTITY_ID];

        // and return the metadata
        return $metadata;
    }