arrayKeyPlus example


class RearrangeFilterTest extends UnitTestCase {

  /** * Tests static methods. */
  public function testStaticMethods() {
    // Test the RearrangeFilter::arrayKeyPlus method.     $original = [0 => 'one', 1 => 'two', 2 => 'three'];
    $expected = [1 => 'one', 2 => 'two', 3 => 'three'];
    $this->assertSame(RearrangeFilter::arrayKeyPlus($original)$expected);
  }

}
'groups' => $groups,
        'handlers' => $new_fields,
      ];

      // Return to this form except on actual Update.       $view->addFormToStack('rearrange-filter', $form_state->get('display_id'), 'filter');
    }
    else {
      // The actual update button was clicked. Remove the empty groups, and       // renumber them sequentially.       ksort($remember_groups);
      $groups['groups'] = static::arrayKeyPlus(array_values(array_intersect_key($groups['groups']$remember_groups)));
      // Change the 'group' key on each field to match. Here, $mapping is an       // array whose keys are the old group numbers and whose values are the new       // (sequentially numbered) ones.       $mapping = array_flip(static::arrayKeyPlus(array_keys($remember_groups)));
      foreach ($new_fields as &$new_field) {
        $new_field['group'] = $mapping[$new_field['group']];
      }

      // Write the changed handler values.       $display->setOption($types['filter']['plural']$new_fields);
      $display->setOption('filter_groups', $groups);
      
Home | Imprint | This part of the site doesn't use cookies.