simialbi / yii2-schema-org

Schema.org yii2 representation and helpers for json-ld generation
MIT License
17 stars 4 forks source link

Breadcrumbs issues #6

Closed machour closed 5 years ago

machour commented 5 years ago

hey :)

Noticed a few issues with breadcrumbs:

  1. Old classes are still used: https://github.com/simialbi/yii2-schema-org/blob/master/src/helpers/JsonLDHelper.php#L38

  2. The produced JSON LD is invalid, because all entries should contain an url. Currently the code looks like this:

    if (is_array($breadcrumb)) {
    $listItem->item = [
        '@id' => Url::to(ArrayHelper::getValue($breadcrumb, 'url', ''), true),
        'name' => ArrayHelper::getValue($breadcrumb, 'label', '')
    ];
    } else {
    $listItem->item = [ <- bogus item
        'name' => $breadcrumb // 
    ];
    }

A fix could be to assume that the non-array item is always the one at the end, and set its url to the current URL ('@id' => Yii::$app->request->absoluteUrl)

simialbi commented 5 years ago

Thank you for this input. I fixed the auto generated output like you proposed. The 1. isn't a bug. It works as it should. Autocreation of Json+LD breadcrumbs works only if you use it with default namespace.