You are here

public static function FormElement::getMaxDelta in Modules weight 8

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

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.

Parameters

int $weight: The weight.

Return value

int The weight.

2 calls to FormElement::getMaxDelta()
FormElementTest::testGetMaxDelta in tests/src/Unit/Utility/FormElementTest.php
Tests the max delta with FormElement::getMaxDelta().
ModulesListForm::buildForm in src/Form/ModulesListForm.php
Form constructor.

File

src/Utility/FormElement.php, line 25

Class

FormElement
Provides Form Element helper methods.

Namespace

Drupal\modules_weight\Utility

Code

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;
}