Navigation

  • index
  • next |
  • previous |
  • Sulu 2.1 documentation »
  • Cookbook »

Provider for CKEditor Internal-Sulu-Link¶

LinkProvider are used to load data for the “Internal-Sulu-Link” Plugin for the CKEditor. It returns an array of LinkItem instances, identified by ids which will be passed to the LinkProviderInterface::preload function. This feature can be used by the CKEditor Plugin “Sulu-Internal-Link” or by adding Markup to your twig-templates (see following example and the chapter MarkupBundle).

<sulu-link provider="page" href="123-123-123"/>

The LinkItem consists of the following properties:

  • id
  • title
  • url
  • published

Example¶

This example assumes that the entities will be selected by a datagrid. For this we already build an abstract implementation which can be configured with the LinkConfigurationBuilder.

<?php

namespace AppBundle\Link;

use Sulu\Bundle\PageBundle\Markup\Link\LinkConfiguration;
use Sulu\Bundle\MarkupBundle\Markup\Link\LinkConfigurationBuilder;
use Sulu\Bundle\PageBundle\Markup\Link\LinkItem;
use Sulu\Bundle\PageBundle\Markup\Link\LinkProviderInterface;

class LinkProvider implements LinkProviderInterface
{
    /**
     * {@inheritdoc}
     */
    public function getConfiguration()
    {
        return LinkConfigurationBuilder::create()
            ->setTitle($this->translator->trans('sulu_page.pages', [], 'admin'))
            ->setResourceKey('...') // the resourceKey of the entity that should be loaded
            ->setListAdapter('column_list')
            ->setDisplayProperties(['title'])
            ->setOverlayTitle($this->translator->trans('sulu_page.single_selection_overlay_title', [], 'admin'))
            ->setEmptyText($this->translator->trans('sulu_page.no_page_selected', [], 'admin'))
            ->setIcon('su-document')
            ->getLinkConfiguration();
    }

    /**
     * {@inheritdoc}
     */
    public function preload(array $hrefs, $locale, $published = true)
    {
        if (0 === count($hrefs)) {
            return [];
        }

        $items = ...; // load items by id
        foreach ($items as $item) {
            $result[] = new LinkItem(...); // create link-item foreach item
        }

        return $result;
    }
}

Now you can create a service for this class and add the tag with the corresponding resourceKey <tag name=”sulu.link.provider” alias=”{resourceKey}”/>.

Logo

Table of Contents

  • The Book
  • Cookbook
    • Caching with Varnish
    • Maintenance Mode
    • Securing your application
    • Pass additional data to your template using a custom controller
    • Custom error page
    • Extend Entities
    • How to implement an entity extensible?
    • Migrate existing content data on template change
    • Using Jackrabbit
    • Using Elasticsearch
    • DataProvider for SmartContent
    • Filter pages by a property using a custom SmartContent DataProvider
    • System-Collections
    • Adding new Webspace
    • How to manage analytics?
    • How to change the default locale provider?
    • Using default snippets for managing page-independent data
    • How to Override Sulu’s default Directory Structure
    • How to manage custom-urls?
    • How to deactivate the RequestAnalyzer?
    • How to use the RequestAnalyzer with ESI requests?
    • Server Configuration
    • How to add localizations with the localization provider?
    • Provider for CKEditor Internal-Sulu-Link
    • Provider for XML-Sitemap
    • Improve Sitemap Speed
    • HTTPS
    • Generating thumbnails for video files with ffmpeg
    • Store Media in an external Storage
    • Using Webpack Encore for your website assets
    • Adding tabs to Sulu’s Admin UI
    • Display values from a service in a select
    • Provide Sulu twig template attributes in your controller
  • Reference
  • Bundles
  • Developer Guide
  • Upgrades

Related Topics

  • Documentation overview
    • Cookbook
      • Previous: How to add localizations with the localization provider?
      • Next: Provider for XML-Sitemap

This Page

  • Show Source

Quick search

Navigation

  • index
  • next |
  • previous |
  • Sulu 2.1 documentation »
  • Cookbook »