定制 inforca/ibexa-json-ld-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

inforca/ibexa-json-ld-bundle

Composer 安装命令:

composer require inforca/ibexa-json-ld-bundle

包简介

Bundle pour intégration de jsonLD

README 文档

README

Description:

A bundle for Ibexa that lets you add a JSONLD schema in content full views for a dedicated content type (By configuring the schema)

img.png

Requirements:

  • Ibexa v4.x
  • PHP 8.x

Install:

Add this line to the composer.json dependencies:

"inforca/ibexa-json-ld-bundle": "dev-main",

And into "repositories" p of composer.json:

    "repositories": {
        ...,
        
        "inforca-ibexa-json-ld-bundle": {
            "type": "vcs",
            "url": "https://git.inforca.mc/webforca/bundles/ibexa-json-ld-bundle"
        }
    }

.. then run

composer update inforca/ibexa-json-ld-bundle

Look after changes:

Check your file config/bundles.php

Add the next line, if it is not already present, into your array of charged bundles

Inforca\IbexaJsonLdBundle\InforcaJsonLdBundle::class => ['all' => true],

Use

Create schema.json file

In public folder, create "jsonLd" folder, and inside create a file called "schema.json"

img.png

Specifics schemas (optionnal)

In order to be able to customise its schemas for different siteaccess, you can configure and create your own files, wherever you want, as long as the file is in ‘json’ format and has the file extension ‘.json’.

In addition, you can configure a schema for a type of content (‘article’ for example), in your file dedicated to a siteaccess and also configure it in the default ‘schema.json’. The purpose of this is to have a fallback configuration in the event that you are no longer on this siteaccess and other sites need an ‘article’ configuration for another use.

To do this, you need to add a configuration under the ‘parameters’ configuration key in your configuration file, such as:


### Find your corresponding schema

Go to https://schema.org/

Find the corresponding schema to the content type you want a schema implemented and loaded in <head> section of your website

Example for an **article** or **newspost** (https://schema.org/NewsArticle):

```json
{
  "@context": "https://schema.org",
  "@type": "NewsArticle",
  "url": "http://www.bbc.com/news/world-us-canada-39324587",
  "publisher":{
    "@type":"Organization",
    "name":"BBC News",
    "logo":"http://www.bbc.co.uk/news/special/2015/newsspec_10857/bbc_news_logo.png?cb=1"
  },
  "headline": "Trump Russia claims: FBI's Comey confirms investigation of election 'interference'",
  "mainEntityOfPage": "http://www.bbc.com/news/world-us-canada-39324587",
  "articleBody": "Director Comey says the probe into last year's US election would assess if crimes were committed.",
  "image":[
    "http://ichef-1.bbci.co.uk/news/560/media/images/75306000/jpg/_75306515_line976.jpg",
  ],
  "datePublished":"2017-03-20T20:30:54+00:00"
}
```

Add the schema to the **schema.json** file created juste before by adding a new empty json table.
Create an other json table inside the empty one, with a table key which is the **content type identifier** that you configured
in back office, for the schema corresponding.

For example, with a content type called "article" in back office, the schema.json file looks like:


```json
{
  "article": {
    "@context": "https://schema.org",
    "@type": "NewsArticle",
    "url": "http://www.bbc.com/news/world-us-canada-39324587",
    "publisher": {
      "@type": "Organization",
      "name": "BBC News",
      "logo": "http://www.bbc.co.uk/news/special/2015/newsspec_10857/bbc_news_logo.png?cb=1"
    },
    "headline": "Trump Russia claims: FBI's Comey confirms investigation of election 'interference'",
    "mainEntityOfPage": "http://www.bbc.com/news/world-us-canada-39324587",
    "articleBody": "Director Comey says the probe into last year's US election would assess if crimes were committed.",
    "image": [
      "http://ichef-1.bbci.co.uk/news/560/media/images/75306000/jpg/_75306515_line976.jpg"
    ],
    "datePublished": "2017-03-20T20:30:54+00:00"
  },
}
```


If you want to add an other schema for an other content type, add it below the previous one like:

```json
{
  "article": {
    ...
  },
  "event": {
    "@context": "https://schema.org",
    "@type": "MusicGroup",
    "event": [
      {
        "@type": "Event",
        "location": "Memphis, TN, US",
        "offers": "ticketmaster.com/foofighters/may20-2011",
        "startDate": "2011-05-20",
        "url": "foo-fighters-may20-fedexforum"
      },
      {
        "@type": "Event",
        "location": "Council Bluffs, IA, US",
        "offers": "ticketmaster.com/foofighters/may23-2011",
        "startDate": "2011-05-23",
        "url": "foo-fighters-may23-midamericacenter"
      }
    ],
    "image": [
      "foofighters-1.jpg",
      "foofighters-2.jpg",
      "foofighters-3.jpg"
    ],
    "name": "Foo Fighters",
  },
}
```

### Call the JSONLD controller

In your pagelayout.html.twig, in the **<head>** section, call the controller which will inject the schema corresponding to your content
in your page.

```
{% if content %}
    {{ render_esi(controller('Inforca\\IbexaJsonLdBundle\\Controller\\JsonLdController::generateJsonLdSchema', {
        contentId: content.id,
    })) }}
{% endif %}
```


### Fields mapping instructions

We want now programmatically get informations from your back office (title, description, image, relation field information...),
to schematize your content following the content type schema configured in schema.json file.

We can get informations from a field of the current content, metadescription informations, from a related content field
(related content title for example), a boolean etc.


#### **FIELD VALUE**

We use the **"#"** instruction followed by the **field identifier** you want to get the value.

Example:

- **#title** will return the title content field value.

```json
"article": {
...
"publisher": {
...
"name": "#title",
...
}
},
```

#### **BOOLEAN VALUE**

When you get boolean field value, you will follow the instructions above (to get a field value) for example.

```json
"article": {
...
"publisher": {
...
"isPublished": "#isPublished" // will return true or false,
...
}
},
```

You can change the return value of the boolean, example:

```json
"article": {
...
"publisher": {
...
"isPublished": "#isPublished(yes|no)" // will return yes or no,
...
}
},
```

You can of course combine instructions, for example if your boolean field is in a related content
of your current content:

```json
"article": {
...
"publisher": {
...
"isPublished": "*related_field_identifier#isPublished(of course|not at all)" // will return yes or no,
...
}
},
```

#### **METADATA FIELD VALUE**

We use the **"@"** instruction followed by the **metadata field identifier** you want to get the value.

Example:

- **@creationDate** will return the creation date metadata field value of the current content.
- **@modificationDate** will return the modification date metadata field value of the current content.
- **@url** will return the current content URL.

```json
"article": {
...
"publisher": {
...
"createdAt": "@creationDate",
"modifiedAt": "@modificationDate",
"url": "@url",
...
}
},
```

Some others metadata fields:

- @identifier
- @contentID
- @modificationDate


#### **RELATED CONTENT FIELD VALUE**

We use the **"*"** instruction followed by the identifier of the relation field.
Then, we add the instruction **"#"** seen above to get the field value followed by the field identifier of the related content field you want to get.

Example: I want to get the **name** of the **author** which is in **relation** in our **current content.**

```json
"article": {
...
"author": [{
"@type": "Person",
"name": "*related_author#name"
}]
},
```

#### **SUBFIELD VALUE (of the current content OR related content)**

We use the **">"** instruction followed by the **subfield identifier** you want to get the value.
Example with the Ibexa "address" field which is composed by subfields.

If my "address" field is in the current content type definition, you can get the value like this:

```json
"address": {
"@type": "PostalAddress",
"streetAddress": "#adresse>street",
"addressRegion": "#adresse>region",
"postalCode": "#adresse>postal_code",
"addressLocality": "#adresse>locality"
}
```

You can also combine instructions like if my "address" field is in a content which is related to the current content for example,
you can get the value like this:


```json
"address": {
"@type": "PostalAddress",
"streetAddress": "*related_place#adresse>street",
"addressRegion": "*related_place#adresse>region",
"postalCode": "*related_place#adresse>postal_code",
"addressLocality": "*related_place#adresse>locality"
}
```

### Enable or Disable bundle as you want, per siteaccess (optionnal)

By default, the bundle is activated at configuration level for all your sites.
If you wish to deactivate it for some or activate it only for certain siteaccess, you can add these configurations under the ‘parameters’ key.

Example:

The bundle is enabled by default for all siteaccess, so i override the default configuration to disable for all.
```inforca_jsonld_bundle.default.enable_jsonld_schemas: false```

Then, i enable the bundle only on a particular siteaccess in dedicated config file:

```inforca_jsonld_bundle.<your_siteaccess>.enable_jsonld_schemas: true```

inforca/ibexa-json-ld-bundle 适用场景与选型建议

inforca/ibexa-json-ld-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 230 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 06 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「jsonld」 「core」 「ibexa」 「inforca」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 inforca/ibexa-json-ld-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 inforca/ibexa-json-ld-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 inforca/ibexa-json-ld-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 230
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2025-06-03