pixeldev/sulu-socialbundle

Sulu的社交媒体工具

2.6.1 2024-05-22 07:00 UTC

This package is not auto-updated.

Last update: 2024-09-11 08:21:02 UTC


README

GitHub release (with filter) Dependency

演示

这是一个用于轻松管理社交媒体的Sulu捆绑包。

要求

  • PHP >= 8.0
  • Sulu >= 2.4.*
  • Symfony >= 5.4
  • Composer

安装

安装捆绑包

执行以下composer命令,将捆绑包添加到项目的依赖项中

composer require pixeldev/sulu-socialbundle --with-all-dependencies

启用捆绑包

通过将其添加到项目config/bundles.php文件中已注册捆绑包的列表中,来启用捆绑包

return [
    /* ... */
    Pixel\SocialBundle\SocialBundle::class => ['all' => true],
];

更新架构

bin/console do:sch:up --force

捆绑包配置

routes_admin.yaml中定义Admin Api路由

social.settings_api:
  type: rest
  prefix: /admin/api
  resource: pixel_social.settings_route_controller
  name_prefix: social.

使用

通用使用

要访问社交媒体设置,在管理界面中,转到设置部分并点击“社交媒体管理”。一旦进入表单,您将看到块内容类型。

此块由一种类型组成,“社交媒体”类型。它由两个字段组成

  • 社交媒体名称
  • 社交媒体链接

社交媒体名称字段是一个选择框,您可以在其中选择您想要的社交媒体。

社交媒体链接是一个链接字段类型。

不要忘记点击“保存”,以便将信息存储并可用。

Twig扩展

此捆绑包包含几个twig函数,可以帮助您渲染您填写的社交媒体。

social_settings():返回您提供的所有社交媒体。无需参数。

使用示例

{% set socialSettings = social_settings() %}
<ul class="social-list">
    {% if socialSettings is defined %}
        {% for socialMedia in socialSettings.socialMedias %}
            <li>
                <a href="{{ socialMedia.socialMediaUrl }}" target="_blank">
                    {{ socialMedia.socialMediaName }}
                </a>
            </li>
        {% endfor %}
    {% endif %}
</ul>

facebook_share(link, title):返回一个链接到Facebook上的分享。它接受两个参数

  • link:您想要分享的链接
  • title:将在Facebook上的共享链接上显示的文本

使用示例

<a {{ facebook_share("https://your-site.com/product/my-product", "My awsome website") }}>Share on Facebook</a>

twitter_share(link, title, origin):返回一个链接到Twitter上的分享。它接受三个参数

  • link:您想要分享的链接
  • title:将在Twitter上的共享链接上显示的文本
  • origin:共享的来源

使用示例

<a href="{{ twitter_share('https://your-site.com/product/my-product', 'My awsome website', 'https://your-site.com') }}>Share on Twitter</a>

linkedin_share(link):返回一个链接到LinkedIn上的分享。它接受一个参数

  • link:您想要分享的链接

使用示例

<a href="{{ linkedin_share('https://your-site.com/product/my-product') }}>Share on LinkedIn</a>

whatsapp_share(text, link):返回一个链接到WhatsApp上的分享。它接受两个参数

  • text:将在WhatsApp上的共享链接上显示的文本
  • link:您想要分享的链接

使用示例

<a href="{{ whatsapp_share('https://your-site.com/product/my-product') }}>Share on WhatsApp</a>

pinterest_share(link):返回一个链接到Pinterest上的分享。它接受一个参数

  • link:您想要分享的链接

使用示例

<a href="{{ pinterest_share('https://your-site.com/product/my-product') }}>Share on Pinterest</a>

social_media_logo(name):渲染指定社交媒体的标志。它接受一个参数

  • name:社交媒体名称

使用示例

{{ social_media_logo(socialMedia.socialMediaName) }}

贡献

您可以为这个捆绑包做出贡献。您必须做的唯一一件事是尊重我们实施的编码标准。您可以在ecs.php文件中找到它们。