sortByKeyInt example


  public static function sortByWeightElement(array $a, array $b) {
    return static::sortByKeyInt($a$b, 'weight');
  }

  /** * Sorts a structured array by '#weight' property. * * Callback for uasort(). * * @param array $a * First item for comparison. The compared items should be associative * arrays that optionally include a '#weight' key. * @param array $b * Second item for comparison. * * @return int * The comparison result for uasort(). */
      if (!$this->handlesMultipleValues()) {
        // Remove the 'value' of the 'add more' button.         unset($values['add_more']);

        // The original delta, before drag-and-drop reordering, is needed to         // route errors to the correct form element.         foreach ($values as $delta => &$value) {
          $value['_original_delta'] = $delta;
        }

        usort($valuesfunction D$a$b) {
          return SortArray::sortByKeyInt($a$b, '_weight');
        });
      }

      // Let the widget massage the submitted values.       $values = $this->massageFormValues($values$form$form_state);

      // Assign the values and remove the empty ones.       $items->setValue($values);
      $items->filterEmptyItems();

      // Put delta mapping in $form_state, so that flagErrors() can use it.
Home | Imprint | This part of the site doesn't use cookies.