1

I want to create a filter text module for drupal 8.

emtfilter/src/Plugin/Filter/emtfilter.php

/**
 * @file
 * Contains \Drupal\emtfilter\Plugin\Filter\emtfilter.
 */

namespace Drupal\emtfilter\Plugin\Filter;

use Drupal\Core\Form\FormStateInterface;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterBase;

/**
 * Text filter for highlighting PHP source code.
 *
 * @Filter(
 *   id = "emtfilter",
 *   module = "emtfilter",
 *   title = @Translation("Tipograf"),
 *   description = @Translation("Tipograf"),
 *   type = Drupal\filter\Plugin\FilterInterface::TYPE_HTML_RESTRICTOR,
 * )
 */
class emtfilter extends FilterBase { 


  /**
   * {@inheritdoc}
   */
  public function tips($long = FALSE) {
    if ($long) {
      return t('text1r-');
    }
    else {
      return t('text2r-');
    }
  }

  /**
   * {@inheritdoc}
   */
  public function process($text, $langcode) {
        return new FilterProcessResult($text);
  }    
}

After clearing cashe everything is ok. But when I visit some forms with textfields second time, Drupal generates this error:

Notice: _filter_tips(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "Drupal\emtfilter\Plugin\Filter\emtfilter" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in _filter_tips() (line 350 of core/modules/filter/filter.module).
_filter_tips('full_html', ) (Line: 378)
template_preprocess_filter_guidelines(Array, 'filter_guidelines', Array) (Line: 293)

And my tips disappear. What am I do wrong?

  • It's probably the use of t(). Can you change to $this->t? – mradcliffe Apr 24 '16 at 17:02
  • I tried - all the same. This is a problem with cashe, as I think. In the first launch it works properly, including translation. – Crantisz Apr 24 '16 at 17:34
0

I made a mistake in the letter case in the class file (emtFilter.php -> emtfilter.php)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.