You are here

class FormElement in Modules weight 8

Same name and namespace in other branches
  1. 8.2 src/Utility/FormElement.php \Drupal\modules_weight\Utility\FormElement

Provides Form Element helper methods.

Hierarchy

Expanded class hierarchy of FormElement

2 files declare their use of FormElement
FormElementTest.php in tests/src/Unit/Utility/FormElementTest.php
ModulesListForm.php in src/Form/ModulesListForm.php

File

src/Utility/FormElement.php, line 10

Namespace

Drupal\modules_weight\Utility
View source
class FormElement {

  /**
   * Prepares the delta for the weight field.
   *
   * If a module has a weight higher then 100 (or lower than 100), it will use
   * that value as delta and the '#weight' field will turn into a textfield most
   * likely.
   *
   * @param int $weight
   *   The weight.
   *
   * @return int
   *   The weight.
   */
  public static function getMaxDelta($weight) {
    $delta = 100;

    // Typecasting to int.
    $weight = (int) $weight;
    if ($weight > $delta) {
      return $weight;
    }
    if ($weight < -100) {
      return $weight * -1;
    }
    return $delta;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormElement::getMaxDelta public static function Prepares the delta for the weight field.