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 beforeunserialize()
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?
t()
. Can you change to$this->t
?