"Fossies" - the Fresh Open Source Software Archive

Member "contao-4.11.5/core-bundle/src/Picker/AbstractInsertTagPickerProvider.php" (23 Jun 2021, 1435 Bytes) of package /linux/www/contao-4.11.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AbstractInsertTagPickerProvider.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 declare(strict_types=1);
    4 
    5 /*
    6  * This file is part of Contao.
    7  *
    8  * (c) Leo Feyer
    9  *
   10  * @license LGPL-3.0-or-later
   11  */
   12 
   13 namespace Contao\CoreBundle\Picker;
   14 
   15 abstract class AbstractInsertTagPickerProvider extends AbstractPickerProvider
   16 {
   17     /**
   18      * Returns the configured insert tag or the default one.
   19      */
   20     protected function getInsertTag(PickerConfig $config): string
   21     {
   22         if ($insertTag = $config->getExtraForProvider('insertTag', $this->getName())) {
   23             return (string) $insertTag;
   24         }
   25 
   26         return $this->getDefaultInsertTag();
   27     }
   28 
   29     /**
   30      * Returns the default insert tag.
   31      */
   32     abstract protected function getDefaultInsertTag(): string;
   33 
   34     /**
   35      * Splits an insert tag at the placeholder (%s) and returns the chunks.
   36      */
   37     protected function getInsertTagChunks(PickerConfig $config): array
   38     {
   39         return explode('%s', $this->getInsertTag($config), 2);
   40     }
   41 
   42     /**
   43      * Returns the value without the surrounding insert tag chunks.
   44      */
   45     protected function getInsertTagValue(PickerConfig $config)
   46     {
   47         return str_replace($this->getInsertTagChunks($config), '', $config->getValue());
   48     }
   49 
   50     /**
   51      * Checks if the value matches the insert tag.
   52      */
   53     protected function isMatchingInsertTag(PickerConfig $config): bool
   54     {
   55         return false !== strpos($config->getValue(), $this->getInsertTagChunks($config)[0]);
   56     }
   57 }