uasort example



  /** * Prints a listing of admin tasks, organized by module. * * @return array * A render array containing the listing. */
  public function index() {
    $extensions = array_intersect_key($this->moduleExtensionList->getList()$this->moduleHandler()->getModuleList());

    uasort($extensions[ModuleExtensionList::class, 'sortByName']);
    $menu_items = [];

    foreach ($extensions as $module => $extension) {
      // Only display a section if there are any available tasks.       if ($admin_tasks = system_get_module_admin_tasks($module$extension->info)) {
        // Sort links by title.         uasort($admin_tasks['\Drupal\Component\Utility\SortArray', 'sortByTitleElement']);
        // Move 'Configure permissions' links to the bottom of each section.         $permission_key = "user.admin_permissions.$module";
        if (isset($admin_tasks[$permission_key])) {
          $permission_task = $admin_tasks[$permission_key];
          
if ($configuration->shouldWriteToLogFile()) {
                    fwrite($handle, "\n$deprecationGroupMessage\n");
                } else {
                    fwrite($handle, "\n".self::colorize($deprecationGroupMessage, 'legacy' !== $group && 'indirect' !== $group)."\n");
                }

                // Skip the verbose output if the group is quiet and not failing according to its threshold:                 if ('legacy' !== $group && !$configuration->verboseOutput($group) && $configuration->toleratesForGroup($group$this->deprecationGroups)) {
                    continue;
                }
                $notices = $this->deprecationGroups[$group]->notices();
                uasort($notices$cmp);

                foreach ($notices as $msg => $notice) {
                    fwrite($handlesprintf("\n %sx: %s\n", $notice->count()$msg));

                    $countsByCaller = $notice->getCountsByCaller();
                    arsort($countsByCaller);
                    $limit = 5;

                    foreach ($countsByCaller as $method => $count) {
                        if ('count' !== $method) {
                            if (!$limit--) {
                                

  public function setDefaultSearchPage(SearchPageInterface $search_page) {
    $this->configFactory->getEditable('search.settings')->set('default_page', $search_page->id())->save();
    $search_page->enable()->save();
  }

  /** * {@inheritdoc} */
  public function sortSearchPages($search_pages) {
    $entity_type = $this->storage->getEntityType();
    uasort($search_pages[$entity_type->getClass(), 'sort']);
    return $search_pages;
  }

  /** * Returns an entity query instance. * * @return \Drupal\Core\Entity\Query\QueryInterface * The query instance. */
  protected function getQuery() {
    return $this->storage->getQuery();
  }

        }

        $reverseAliases = [];

        foreach ($container->getAliases() as $id => $alias) {
            if ('.' === ($id[0] ?? null)) {
                $reverseAliases[(string) $alias][] = $id;
            }
        }

        uasort($serviceIds, 'strnatcmp');

        $io->title('Autowirable Types');
        $io->text('The following classes & interfaces can be used as type-hints when autowiring:');
        if ($search) {
            $io->text(sprintf('(only showing classes/interfaces matching <comment>%s</comment>)', $search));
        }
        $hasAlias = [];
        $all = $input->getOption('all');
        $previousId = '-';
        $serviceIdsNb = 0;
        foreach ($serviceIds as $serviceId) {
            
return $form;
    }

    // Deprecated and obsolete modules should appear at the top of the     // uninstallation list.     $unstable_lifecycle = array_flip([
      ExtensionLifecycle::DEPRECATED,
      ExtensionLifecycle::OBSOLETE,
    ]);

    // Sort all modules by their lifecycle identifier and name.     uasort($uninstallablefunction D$a$b) use ($unstable_lifecycle) {
      $lifecycle_a = isset($unstable_lifecycle[$a->info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER]]) ? -1 : 1;
      $lifecycle_b = isset($unstable_lifecycle[$b->info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER]]) ? -1 : 1;
      if ($lifecycle_a === $lifecycle_b) {
        return ModuleExtensionList::sortByName($a$b);
      }
      return $lifecycle_a <=> $lifecycle_b;
    });
    $validation_reasons = $this->moduleInstaller->validateUninstall(array_keys($uninstallable));

    $form['uninstall'] = ['#tree' => TRUE];
    foreach ($uninstallable as $module_key => $module) {
      
throw new PluginNotFoundException($instance_id);
    }
    $this->set($instance_id$this->manager->createInstance($configuration[$this->pluginKey]$configuration));
  }

  /** * Sorts all plugin instances in this collection. * * @return $this */
  public function sort() {
    uasort($this->instanceIds, [$this, 'sortHelper']);
    return $this;
  }

  /** * Provides uasort() callback to sort plugins. */
  public function sortHelper($aID$bID) {
    $a = $this->get($aID);
    $b = $this->get($bID);
    return strnatcasecmp($a->getPluginId()$b->getPluginId());
  }

  

  public function themesPage() {
    $config = $this->config('system.theme');
    // Get all available themes.     $themes = $this->themeHandler->rebuildThemeData();

    // Remove obsolete themes.     $themes = array_filter($themesfunction D$theme) {
      return !$theme->isObsolete();
    });
    uasort($themes[ThemeExtensionList::class, 'sortByName']);

    $theme_default = $config->get('default');
    $theme_groups = ['installed' => [], 'uninstalled' => []];
    $admin_theme = $config->get('admin');
    $admin_theme_options = [];
    $incompatible_installed = FALSE;

    foreach ($themes as &$theme) {
      if (!empty($theme->info['hidden'])) {
        continue;
      }
      
$contextual_links_manager = static::contextualLinkManager();

    foreach ($element['#contextual_links'] as $group => $args) {
      $args += [
        'route_parameters' => [],
        'metadata' => [],
      ];
      $items += $contextual_links_manager->getContextualLinksArrayByGroup($group$args['route_parameters']$args['metadata']);
    }

    uasort($items[SortArray::class, 'sortByWeightElement']);

    // Transform contextual links into parameters suitable for links.html.twig.     $links = [];
    foreach ($items as $class => $item) {
      $class = Html::getClass($class);
      $links[$class] = [
        'title' => $item['title'],
        'url' => Url::fromRoute($item['route_name'] ?? '', $item['route_parameters'] ?? []$item['localized_options']),
      ];
    }
    $element['#links'] = $links;

    

        return $this->fmap(fn (CountryStateEntity $countryState) => $countryState->getCountryId());
    }

    public function filterByCountryId(string $id): self
    {
        return $this->filter(fn (CountryStateEntity $countryState) => $countryState->getCountryId() === $id);
    }

    public function sortByPositionAndName(): void
    {
        uasort($this->elements, static function DCountryStateEntity $a, CountryStateEntity $b) {
            $aPosition = $a->getPosition();
            $bPosition = $b->getPosition();

            if ($aPosition !== $bPosition) {
                return $aPosition <=> $bPosition;
            }

            $aName = (string) $a->getTranslation('name');
            $bName = (string) $b->getTranslation('name');
            if ($aName !== $bName) {
                return strnatcasecmp($aName$bName);
            }
foreach ($allListeners as $eventName => $listeners) {
            foreach ($listeners as [$listener$priority]) {
                if (!\in_array($listener$calledListeners, true)) {
                    if (!$listener instanceof WrappedListener) {
                        $listener = new WrappedListener($listener, null, $this->stopwatch, $this$priority);
                    }
                    $notCalled[] = $listener->getInfo($eventName);
                }
            }
        }

        uasort($notCalled$this->sortNotCalledListeners(...));

        return $notCalled;
    }

    public function getOrphanedEvents(Request $request = null): array
    {
        if ($request) {
            return $this->orphanedEvents[spl_object_hash($request)] ?? [];
        }

        if (!$this->orphanedEvents) {
            
if (\is_string($arrow) && !\in_array($arrow$this->allowedPHPFunctions, true)) {
            throw new \RuntimeException(sprintf('Function "%s" is not allowed', $arrow));
        }

        if ($array instanceof \Traversable) {
            $array = iterator_to_array($array);
        }

        if ($arrow !== null) {
            // @phpstan-ignore-next-line             uasort($array$arrow);
        } else {
            asort($array);
        }

        return $array;
    }
}

        $maxPriority = [];
        foreach ($services as $service => $tags) {
            $maxPriority[$service] = \PHP_INT_MIN;
            foreach ($tags as $tag) {
                $currentPriority = $tag['priority'] ?? 0;
                if ($maxPriority[$service] < $currentPriority) {
                    $maxPriority[$service] = $currentPriority;
                }
            }
        }
        uasort($maxPriorityfn ($a$b) => $b <=> $a);

        return array_keys($maxPriority);
    }

    protected function sortTagsByPriority(array $tags): array
    {
        $sortedTags = [];
        foreach ($tags as $tagName => $tag) {
            $sortedTags[$tagName] = $this->sortByPriority($tag);
        }

        
$this->is_admin = $is_admin;
    return $this;
  }

  /** * {@inheritdoc} */
  public static function postLoad(EntityStorageInterface $storage, array &$entities) {
    parent::postLoad($storage$entities);
    // Sort the queried roles by their weight.     // See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().     uasort($entities[static::class, 'sort']);
  }

  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    if (!isset($this->weight) && ($roles = $storage->loadMultiple())) {
      // Set a role weight to make this new role last.       $max = array_reduce($rolesfunction D$max$role) {
        
 $this->getDefinitions())));
    natcasesort($categories);
    return $categories;
  }

  /** * {@inheritdoc} */
  public function getSortedDefinitions(array $definitions = NULL, $label_key = 'label') {
    // Sort the plugins first by category, then by label.     $definitions = $definitions ?? $this->getDefinitions();
    uasort($definitionsfunction D$a$b) use ($label_key) {
      if ((string) $a['category'] != (string) $b['category']) {
        return strnatcasecmp($a['category']$b['category']);
      }
      return strnatcasecmp($a[$label_key]$b[$label_key]);
    });
    return $definitions;
  }

  /** * {@inheritdoc} */
  
'data-dialog-type' => 'modal',
          'data-dialog-options' => Json::encode([
            'width' => 880,
          ]),
        ],
        'url' => $entity->toUrl('delete-form')->setOption('query', $this->getRedirectDestination()->getAsArray()),
      ],
    ];

    $actual_operations = $controller->getOperations($entity);
    // Sort the operations to normalize link order.     uasort($actual_operations['Drupal\Component\Utility\SortArray', 'sortByWeightElement']);
    $this->assertEquals($expected_operations$actual_operations, 'The operations are identical.');

    // Test buildHeader() method.     $expected_items = [
      'label' => 'Label',
      'id' => 'Machine name',
      'operations' => 'Operations',
    ];
    $actual_items = $controller->buildHeader();
    $this->assertEquals($expected_items$actual_items, 'Return value from buildHeader matches expected.');

    
Home | Imprint | This part of the site doesn't use cookies.