Commit e98bc8b1 authored by Martin Postma's avatar Martin Postma
Browse files

Implement CodeSniffer suggestions.

parent cede6afb
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
name: AutoFloat
type: module
description: A text format filter that adds odd/even classes to images to make them float alternately left and right.
version: VERSION
core: 8.x
configure: autofloat.settings
+3 −2
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Install, update and uninstall functions.
@@ -13,9 +14,9 @@ function autofloat_install() {
  $url = Url::fromRoute('filter.admin_overview');
  $formats_link = \Drupal::l(t('Configuration > Content authoring > Text formats'), $url);

  $text = t('Add the AutoFloat filter to a text format under @formats_link. Move it below other image related filters in the filter processing order.', array(
  $text = t('Add the AutoFloat filter to a text format under @formats_link. Move it below other image related filters in the filter processing order.', [
    '@formats_link' => $formats_link,
  ));
  ]);
  drupal_set_message($text);
}

+4 −3
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Autofloat module: A filter that floats images left and right automatically.
@@ -20,7 +21,7 @@ function autofloat_page_attachments(&$page) {
/**
 * Wrap images in a selector with odd/even classes automatically.
 */
function _autofloat_filter($text, $filter) {
function _autofloat_filter($text) {
  $target = \Drupal::config('autofloat.settings')->get('target');
  $selector = \Drupal::config('autofloat.settings')->get('selector');
  // Divide the variable into two selectors if a comma is found.
+38 −35
Original line number Diff line number Diff line
@@ -5,12 +5,15 @@ namespace Drupal\autofloat\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Class AutofloatSettingsForm.
 */
class AutofloatSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormID() {
  public function getFormId() {
    return 'autofloat_settings';
  }

@@ -18,7 +21,7 @@ class AutofloatSettingsForm extends ConfigFormBase {
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return ['autofloat.settings',];
    return ['autofloat.settings'];
  }

  /**
@@ -27,49 +30,49 @@ class AutofloatSettingsForm extends ConfigFormBase {
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->configFactory->get('autofloat.settings');

    $form['autofloat_start'] = array(
    $form['autofloat_start'] = [
      '#type' => 'radios',
      '#title' => t('Start with the first image on the..'),
      '#options' => array(
        0 => t('right'),
        1 => t('left (swaps "odd" and "even" classes)'),
      ),
      '#title' => $this->t('Start with the first image on the..'),
      '#options' => [
        0 => $this->t('right'),
        1 => $this->t('left (swaps "odd" and "even" classes)'),
      ],
      '#default_value' => $config->get('start'),
      '#description' => t('Clear the site cache to apply changes.'),
    );
    $form['autofloat_css'] = array(
      '#description' => $this->t('Clear the site cache to apply changes.'),
    ];
    $form['autofloat_css'] = [
      '#type' => 'checkbox',
      '#title' => t('Use autofloat.css'),
      '#title' => $this->t('Use autofloat.css'),
      '#default_value' => $config->get('css'),
      '#description' => t('Uncheck to take care of the floating and margins yourself in custom css.'),
    );
    $form['target_settings'] = array(
      '#description' => $this->t('Uncheck to take care of the floating and margins yourself in custom css.'),
    ];
    $form['target_settings'] = [
      '#type' => 'fieldset',
      '#title' => t('Selector/rejector settings'),
      '#description' => t('Images will float unless they have the class "nofloat". Clear the site cache to apply changes. Avoid adding classes manually by defining classes here added by other modules/filters. Use your browser inspector to find them.'),
    );
    $form['target_settings']['autofloat_target'] = array(
      '#title' => $this->t('Selector/rejector settings'),
      '#description' => $this->t('Images will float unless they have the class "nofloat". Clear the site cache to apply changes. Avoid adding classes manually by defining classes here added by other modules/filters. Use your browser inspector to find them.'),
    ];
    $form['target_settings']['autofloat_target'] = [
      '#type' => 'radios',
      '#title' => t('Elements to target'),
      '#options' => array(
        'div' => t('div'),
        'span' => t('span'),
      ),
      '#title' => $this->t('Elements to target'),
      '#options' => [
        'div' => $this->t('div'),
        'span' => $this->t('span'),
      ],
      '#default_value' => $config->get('target'),
      '#description' => t('Clear the site cache to apply changes.'),
    );
    $form['target_settings']['autofloat_selector'] = array(
      '#description' => $this->t('Clear the site cache to apply changes.'),
    ];
    $form['target_settings']['autofloat_selector'] = [
      '#type' => 'textfield',
      '#title' => t('Additional selector classes to float'),
      '#title' => $this->t('Additional selector classes to float'),
      '#default_value' => $config->get('selector'),
      '#description' => t('A "selector" with the class "float" will float all containing content, e.g. the image with a caption under it. Optionally define others. Maximum two, divided by a comma. Example: "caption".'),
    );
    $form['target_settings']['autofloat_rejector'] = array(
      '#description' => $this->t('A "selector" with the class "float" will float all containing content, e.g. the image with a caption under it. Optionally define others. Maximum two, divided by a comma. Example: "caption".'),
    ];
    $form['target_settings']['autofloat_rejector'] = [
      '#type' => 'textfield',
      '#title' => t('Additional div classes to ignore'),
      '#title' => $this->t('Additional div classes to ignore'),
      '#default_value' => $config->get('rejector'),
      '#description' => t('Images nested within any element with the class "nofloat" will NOT float, e.g. a set of thumbnails. Optionally define others. Maximum two, divided by a comma. Example: "flickr-photoset".'),
    );
      '#description' => $this->t('Images nested within any element with the class "nofloat" will NOT float, e.g. a set of thumbnails. Optionally define others. Maximum two, divided by a comma. Example: "flickr-photoset".'),
    ];

    return parent::buildForm($form, $form_state);
  }
+9 −14
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Contains \Drupal\autofloat\Plugin\Filter\AutoFloat.
 */

namespace Drupal\autofloat\Plugin\Filter;

use Drupal\Core\Form\FormStateInterface;
@@ -32,11 +27,11 @@ class AutoFloat extends FilterBase {
    $url = Url::fromRoute('autofloat.settings');
    $config_link = \Drupal::l(t('AutoFloat Filter Settings'), $url);

  $form['notice'] = array(
    '#markup' => t('@config_link are shared by all the text formats where it is enabled.', array(
    $form['notice'] = [
      '#markup' => t('@config_link are shared by all the text formats where it is enabled.', [
        '@config_link' => $config_link,
    )),
  );
      ]),
    ];
    return $form;
  }

@@ -44,7 +39,7 @@ class AutoFloat extends FilterBase {
   * {@inheritdoc}
   */
  public function process($text, $langcode) {
    return new FilterProcessResult(_autofloat_filter($text, $settings));
    return new FilterProcessResult(_autofloat_filter($text));
  }

  /**