Alexander O'Neill
6 years ago
5 changed files with 102 additions and 11 deletions
@ -0,0 +1,86 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace Drupal\bibcite_footnotes\Plugin\Filter; |
||||||
|
|
||||||
|
use Drupal\footnotes\Plugin\Filter\FootnotesFilter; |
||||||
|
use Drupal\Core\Form\FormStateInterface; |
||||||
|
|
||||||
|
/** |
||||||
|
* Provides a base filter for Reference Footnotes filter. |
||||||
|
* |
||||||
|
* @Filter( |
||||||
|
* id = "filter_reference_footnotes", |
||||||
|
* module = "bibcite_footnotes", |
||||||
|
* title = @Translation("Reference Footnotes filter"), |
||||||
|
* description = @Translation("You can insert footnotes directly into texts."), |
||||||
|
* type = \Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_IRREVERSIBLE, |
||||||
|
* cache = FALSE, |
||||||
|
* settings = { |
||||||
|
* "footnotes_collapse" = FALSE, |
||||||
|
* "notes_section_label" = "Notes", |
||||||
|
* "references_section_label" = "References" |
||||||
|
* }, |
||||||
|
* weight = 0 |
||||||
|
* ) |
||||||
|
*/ |
||||||
|
class ReferenceFootnotesFilter extends FootnotesFilter { |
||||||
|
|
||||||
|
/** |
||||||
|
* Object with configuration for reference footnotes. |
||||||
|
* |
||||||
|
* @var object |
||||||
|
*/ |
||||||
|
protected $config; |
||||||
|
|
||||||
|
/** |
||||||
|
* Object with configuration for reference footnotes, where we need editable.. |
||||||
|
* |
||||||
|
* @var object |
||||||
|
*/ |
||||||
|
protected $configEditable; |
||||||
|
|
||||||
|
/** |
||||||
|
* {@inheritdoc} |
||||||
|
*/ |
||||||
|
public function __construct(array $configuration, $plugin_id, array $plugin_definition) { |
||||||
|
parent::__construct($configuration, $plugin_id, $plugin_definition); |
||||||
|
|
||||||
|
$this->config = \Drupal::config('reference_footnotes.settings'); |
||||||
|
$this->configEditable = \Drupal::configFactory() |
||||||
|
->getEditable('reference_footnotes.settings'); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Create the settings form for the filter. |
||||||
|
* |
||||||
|
* @param array $form |
||||||
|
* A minimally prepopulated form array. |
||||||
|
* @param FormStateInterface $form_state |
||||||
|
* The state of the (entire) configuration form. |
||||||
|
* |
||||||
|
* @return array |
||||||
|
* The $form array with additional form elements for the settings of |
||||||
|
* this filter. The submitted form values should match $this->settings. |
||||||
|
*/ |
||||||
|
public function settingsForm(array $form, FormStateInterface $form_state) { |
||||||
|
$settings['footnotes_collapse'] = [ |
||||||
|
'#type' => 'checkbox', |
||||||
|
'#title' => t('Collapse reference footnotes with identical content'), |
||||||
|
'#default_value' => $this->settings['footnotes_collapse'], |
||||||
|
'#description' => t('If two reference footnotes have the exact same content, they will be collapsed into one as if using the same value="" attribute.'), |
||||||
|
]; |
||||||
|
$settings['notes_section_label'] = [ |
||||||
|
'#type' => 'textfield', |
||||||
|
'#title' => t('Notes section label'), |
||||||
|
'#default_value' => $this->settings['notes_section_label'], |
||||||
|
]; |
||||||
|
$settings['references_section_label'] = [ |
||||||
|
'#type' => 'textfield', |
||||||
|
'#title' => $this->t('References section label'), |
||||||
|
'#description' => $this->t('E.g., "Works Cited" for MLA style.'), |
||||||
|
'#default_value' => $this->settings['references_section_label'], |
||||||
|
]; |
||||||
|
return $settings; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue