You are here

class CallbackTagProcessor in Extensible BBCode 8.3

Same name and namespace in other branches
  1. 4.0.x src/Parser/Processor/CallbackTagProcessor.php \Drupal\xbbcode\Parser\Processor\CallbackTagProcessor

A simple wrapper that allows using callable functions as tag plugins.

@package Drupal\xbbcode

Hierarchy

Expanded class hierarchy of CallbackTagProcessor

2 files declare their use of CallbackTagProcessor
TagForm.php in src/Form/TagForm.php
TagFormBase.php in src/Form/TagFormBase.php

File

src/Parser/Processor/CallbackTagProcessor.php, line 12

Namespace

Drupal\xbbcode\Parser\Processor
View source
class CallbackTagProcessor extends TagProcessorBase {

  /**
   * A processing callback.
   *
   * @var callable
   */
  protected $processFunction;

  /**
   * TagProcessor constructor.
   *
   * @param callable $process
   *   A processing callback.
   */
  public function __construct(callable $process) {
    $this->processFunction = $process;
  }

  /**
   * Get the callback.
   *
   * @return callable
   *   A processing callback.
   */
  public function getProcess() : callable {
    return $this->processFunction;
  }

  /**
   * Set the callback.
   *
   * @param callable $process
   *   A processing callback.
   */
  public function setProcess(callable $process) : void {
    $this->processFunction = $process;
  }

  /**
   * {@inheritdoc}
   */
  public function doProcess(TagElementInterface $tag) {
    if ($this->processFunction) {
      return ($this->processFunction)($tag);
    }
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CallbackTagProcessor::$processFunction protected property A processing callback.
CallbackTagProcessor::doProcess public function Override this function to return any printable value. Overrides TagProcessorBase::doProcess
CallbackTagProcessor::getProcess public function Get the callback.
CallbackTagProcessor::setProcess public function Set the callback.
CallbackTagProcessor::__construct public function TagProcessor constructor.
TagProcessorBase::process public function Process a tag match. Overrides TagProcessorInterface::process