You are here

CustomContextualLink.php in Custom Contextual Links 8.2

Namespace

Drupal\ccl\Entity

File

src/Entity/CustomContextualLink.php
View source
<?php

namespace Drupal\ccl\Entity;

use Drupal\Core\Config\Entity\ConfigEntityBase;

/**
 * Defines the Custom Contextual Link entity.
 *
 * @ConfigEntityType(
 *   id = "custom_contextual_link",
 *   label = @Translation("Custom Contextual Link"),
 *   handlers = {
 *     "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
 *     "list_builder" = "Drupal\ccl\CustomContextualLinkListBuilder",
 *     "form" = {
 *       "add" = "Drupal\ccl\Form\CustomContextualLinkForm",
 *       "edit" = "Drupal\ccl\Form\CustomContextualLinkForm",
 *       "delete" = "Drupal\ccl\Form\CustomContextualLinkDeleteForm"
 *     },
 *     "route_provider" = {
 *       "html" = "Drupal\ccl\CustomContextualLinkHtmlRouteProvider",
 *     },
 *   },
 *   config_prefix = "custom_contextual_link",
 *   admin_permission = "administer ccl",
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "label"
 *   },
 *   links = {
 *     "canonical" =
 *   "/admin/config/user-interface/custom_contextual_link/{custom_contextual_link}",
 *     "add-form" = "/admin/config/user-interface/custom_contextual_link/add",
 *     "edit-form" =
 *   "/admin/config/user-interface/custom_contextual_link/{custom_contextual_link}/edit",
 *     "delete-form" =
 *   "/admin/config/user-interface/custom_contextual_link/{custom_contextual_link}/delete",
 *     "collection" = "/admin/config/user-interface/custom_contextual_link"
 *   },
 *   config_export = {
 *     "id",
 *     "label",
 *     "type",
 *     "title",
 *     "link",
 *     "advanced",
 *     "options"
 *   }
 * )
 */
class CustomContextualLink extends ConfigEntityBase implements CustomContextualLinkInterface {

  /**
   * The Custom Contextual Link ID.
   *
   * @var string
   */
  protected $id;

  /**
   * The Custom Contextual Link label.
   *
   * @var string
   */
  protected $label;

  /**
   * The type of link.
   *
   * @var string
   */
  protected $type;

  /**
   * The title of the link.
   *
   * @var string
   */
  protected $title;

  /**
   * The URL of the link.
   *
   * @var string
   */
  protected $link;

  /**
   * Advanced link settings.
   *
   * @var array
   */
  protected $advanced;

  /**
   * Options for the specific link type.
   *
   * @var array
   */
  protected $options;

  /**
   * {@inheritdoc}
   */
  public function getAdvancedOption($option) {
    return isset($this->advanced) && isset($this->advanced[$option]) ? $this->advanced[$option] : NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function getLinkOption($option) {
    return isset($this->options) && isset($this->options[$option]) ? $this->options[$option] : NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function getLinkType() {
    return isset($this->type) ? $this->type : 'node';
  }

  /**
   * {@inheritdoc}
   */
  public function clearOptions() {
    foreach ($this->options as $key => $option) {
      if (strpos($key, $this->type) !== 0) {
        unset($this->options[$key]);
      }
    }
  }

}

Classes

Namesort descending Description
CustomContextualLink Defines the Custom Contextual Link entity.