定制 arillo/silverstripe-links 二次开发

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

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

arillo/silverstripe-links

最新稳定版本:3.0.1

Composer 安装命令:

composer require arillo/silverstripe-links

包简介

Add links to any DataObject

README 文档

README

Latest Stable Version   Total Downloads

Add links to any DataObject.

Requirements

SilverStripe CMS ^6.0

Installation

composer require arillo/silverstripe-links

Usage

Attach the Arillo\Links\LinkExtension to your DataObject via config.yml:

MyDataObject:
  extensions:
    - Arillo\Links\LinkExtension
use SilverStripe\ORM\DataObject;
use Arillo\Links\Link;
use Arillo\Links\LinkExtension;

class MyDataObject extends DataObject
{
    public function getCMSFields()
      {
          $this->beforeUpdateCMSFields(function($fields) {
              // in case you use Link::EDITMODE_PLAIN, you might need
              // to remove the link relation field generated by the scaffolder.
              $fields->removeByName(LinkExtension::FIELD . 'ID')
              $fields->addFieldsToTab(
                  'Root.Main',
                  // add link fields directly to the belonging DataObject.
                  Link::edit_fields(
                      $this,
                      [
                          'mode' => Link::EDITMODE_PLAIN,
                          'showLinkTitle' => true,
                      ]
                  )

                  // or use default editing via HasOneButtonField
                  Link::edit_fields($this)
              );
          });
          return parent::getCMSFields();
      }
}

Inspect Arillo\Links\Link::DEFAULT_FIELDS_CONFIG for all available config keys.

A link can be rendered in templates like this:

<% if $LinkObject.Exists %>
  <% with $LinkObject %>
    <a href="$Href" $TargetAttr.RAW>$Title</a>
  <% end_with %>
<% end_if %>

or use the template of the module:

<% include Link Link=$LinkObject, CssClass=btn btn-primary %>

Extending

Since version 1.x extensibility should have become easier. In this example we are adding the ability to create anchor links to elements:

<?php
namespace Arillo\Extensions;

use SilverStripe\Forms\DropdownField;
use Arillo\Elements\ElementBase;
use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\DataExtension;
use Page;

class LinkExtension extends DataExtension
{
  private static $has_one = [
    'AnchorElement' => ElementBase::class,
  ];
  // alter cms fields
  public function updateLinkCMSFields(
    FieldList $fields,
    DataObject $holderRecord,
    array $config = []
  ) {
    $fieldsPrefix = $config['fieldsPrefix'];
    if ($this->owner->PageID) {
      $fields->push(
        DropdownField::create(
          "{$fieldsPrefix}AnchorElementID",
          'Anker-Element',
          $this->owner
            ->Page()
            ->Elements()
            ->map()
            ->toArray()
        )
          ->setEmptyString('[keins]')
          ->displayIf("{$fieldsPrefix}Type")
          ->isEqualTo('internal')
          ->end()
      );
    }
  }

  // alter href
  public function updateLinkHref($href)
  {
    if (
      $href &&
      $this->owner->Type == 'internal' &&
      $this->owner->AnchorElement()->exists()
    ) {
      $href .= "#{$this->owner->AnchorElement()->URLSegment}";
    }

    return $href;
  }
}

Add extension via config:

Arillo\Links\Link:
  extensions:
    - Arillo\Extensions\LinkExtension

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固