getWeight example


  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];

    if ($default = $this->searchPageRepository->getDefaultSearchPage()) {
      $active_search_pages = $this->searchPageRepository->getActiveSearchPages();
      foreach ($this->searchPageRepository->sortSearchPages($active_search_pages) as $entity_id => $entity) {
        $this->derivatives[$entity_id] = [
          'title' => $entity->label(),
          'route_name' => 'search.view_' . $entity_id,
          'base_route' => 'search.plugins:' . $default,
          'weight' => $entity->getWeight(),
        ];
      }
    }
    return $this->derivatives;
  }

}
'#type' => 'select',
      '#title' => $this->t('Parent terms'),
      '#options' => $options,
      '#default_value' => $parent,
      '#multiple' => TRUE,
    ];

    $form['relations']['weight'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Weight'),
      '#size' => 6,
      '#default_value' => $term->getWeight(),
      '#description' => $this->t('Terms are displayed in ascending order by weight.'),
      '#required' => TRUE,
    ];

    $form['vid'] = [
      '#type' => 'value',
      '#value' => $vocabulary->id(),
    ];

    $form['tid'] = [
      '#type' => 'value',
      
$this->assertEquals($options$this->contextualLinkDefault->getOptions());
  }

  /** * @covers ::getWeight */
  public function testGetWeight($weight = 5) {
    $this->pluginDefinition['weight'] = $weight;
    $this->setupContextualLinkDefault();

    $this->assertEquals($weight$this->contextualLinkDefault->getWeight());
  }

}
'#default_value' => $entity->id(),
      '#required' => TRUE,
      '#disabled' => !$entity->isNew(),
      '#size' => 30,
      '#maxlength' => 64,
      '#machine_name' => [
        'exists' => ['\Drupal\user\Entity\Role', 'load'],
      ],
    ];
    $form['weight'] = [
      '#type' => 'value',
      '#value' => $entity->getWeight(),
    ];

    return parent::form($form$form_state);
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $entity = $this->entity;

    

  protected function assertEntity(int $id, string $expected_language, string $expected_label, string $expected_vid, ?string $expected_description = '', ?string $expected_format = NULL, int $expected_weight = 0, array $expected_parents = [], int $expected_field_integer_value = NULL, int $expected_term_reference_tid = NULL, int|NULL $expected_container_flag = NULL): void {
    /** @var \Drupal\taxonomy\TermInterface $entity */
    $entity = Term::load($id);
    $this->assertInstanceOf(TermInterface::class$entity);
    $this->assertSame($expected_language$entity->language()->getId());
    $this->assertEquals($expected_label$entity->label());
    $this->assertEquals($expected_vid$entity->bundle());
    $this->assertEquals($expected_description$entity->getDescription());
    $this->assertEquals($expected_format$entity->getFormat());
    $this->assertEquals($expected_weight$entity->getWeight());
    $this->assertEquals($expected_parents$this->getParentIDs($id));
    $this->assertHierarchy($expected_vid$id$expected_parents);
    if (!is_null($expected_field_integer_value)) {
      $this->assertTrue($entity->hasField('field_integer'));
      $this->assertEquals($expected_field_integer_value$entity->field_integer->value);
    }
    if (!is_null($expected_term_reference_tid)) {
      $this->assertTrue($entity->hasField('field_integer'));
      $this->assertEquals($expected_term_reference_tid$entity->field_term_reference->target_id);
    }
    if (isset($expected_container_flag)) {
      
$static_cache_id = $this->getCurrentLanguage()->getId();
    }

    if (!isset($this->languages[$static_cache_id][$flags])) {
      // Initialize the language list with the default language and default       // locked languages. These cannot be removed. This serves as a fallback       // list if this method is invoked while the language module is installed       // and the configuration entities for languages are not yet fully       // imported.       $default = $this->getDefaultLanguage();
      $languages = [$default->getId() => $default];
      $languages += $this->getDefaultLockedLanguages($default->getWeight());

      // Load configurable languages on top of the defaults. Ideally this could       // use the entity API to load and instantiate ConfigurableLanguage       // objects. However the entity API depends on the language system, so that       // would result in infinite loops. We use the configuration system       // directly and instantiate runtime Language objects. When language       // entities are imported those cover the default and locked languages, so       // site-specific configuration will prevail over the fallback values.       // Having them in the array already ensures if this is invoked in the       // middle of importing language configuration entities, the defaults are       // always present.

  public static function sort(ShortcutInterface $a, ShortcutInterface $b) {
    $a_weight = $a->getWeight();
    $b_weight = $b->getWeight();
    if ($a_weight == $b_weight) {
      return strnatcasecmp($a->getTitle()$b->getTitle());
    }
    return $a_weight <=> $b_weight;
  }

}
return;
      }

      $build = [
        // @todo Move this to BlockBase in https://www.drupal.org/node/2931040.         '#theme' => 'block',
        '#configuration' => $block->getConfiguration(),
        '#plugin_id' => $block->getPluginId(),
        '#base_plugin_id' => $block->getBaseId(),
        '#derivative_plugin_id' => $block->getDerivativeId(),
        '#in_preview' => $event->inPreview(),
        '#weight' => $event->getComponent()->getWeight(),
      ];

      // Place the $content returned by the block plugin into a 'content' child       // element, as a way to allow the plugin to have complete control of its       // properties and rendering (for instance, its own #theme) without       // conflicting with the properties used above, or alternate ones used by       // alternate block rendering approaches in contributed modules. However,       // the use of a child element is an implementation detail of this       // particular block rendering approach. Semantically, the content returned       // by the block plugin, and in particular, attributes and contextual links       // are information that belong to the entire block. Therefore, we must
foreach ($definitions as $plugin_id => $info) {
      $info += ['access' => AccessResult::allowed()];

      $mock = $this->prophesize(LocalTaskInterface::class);
      $mock->willImplement(CacheableDependencyInterface::class);
      $mock->getRouteName()->willReturn($info['route_name']);
      $mock->getTitle()->willReturn($info['title']);
      $mock->getRouteParameters(Argument::cetera())->willReturn([]);
      $mock->getOptions(Argument::cetera())->willReturn([]);
      $mock->getActive()->willReturn($plugin_id === $active_plugin_id);
      $mock->getWeight()->willReturn($info['weight'] ?? 0);
      $mock->getCacheContexts()->willReturn($info['cache_contexts'] ?? []);
      $mock->getCacheTags()->willReturn($info['cache_tags'] ?? []);
      $mock->getCacheMaxAge()->willReturn($info['cache_max_age'] ?? Cache::PERMANENT);

      $access_manager_map[] = [$info['route_name'][]$this->account, TRUE, $info['access']];

      $map[] = [$info['id'][]$mock->reveal()];
    }

    $this->accessManager->expects($this->any())
      ->method('checkNamedRoute')
      
return (new RuleConfig())
            ->operatorSet(RuleConfig::OPERATOR_SET_NUMBER)
            ->numberField('weight', ['unit' => RuleConfig::UNIT_WEIGHT]);
    }

    private function calculateCartWeight(Cart $cart): float
    {
        $weight = 0.0;

        foreach ($cart->getLineItems()->filterGoodsFlat() as $lineItem) {
            $itemWeight = 0.0;
            if ($lineItem->getDeliveryInformation() !== null && $lineItem->getDeliveryInformation()->getWeight() !== null) {
                $itemWeight = $lineItem->getDeliveryInformation()->getWeight();
            }

            $weight += $itemWeight * $lineItem->getQuantity();
        }

        return $weight;
    }
}
$menu_link = MenuLinkContent::load($id);
    $menu_link = $menu_link->getTranslation($langcode);
    $this->assertInstanceOf(MenuLinkContentInterface::class$menu_link);
    $this->assertSame($title$menu_link->getTitle());
    $this->assertSame($langcode$menu_link->language()->getId());
    $this->assertSame($menu$menu_link->getMenuName());
    $this->assertSame($description$menu_link->getDescription());
    $this->assertSame($enabled$menu_link->isEnabled());
    $this->assertSame($expanded$menu_link->isExpanded());
    $this->assertSame($attributes$menu_link->link->options);
    $this->assertSame($uri$menu_link->link->uri);
    $this->assertSame($weight$menu_link->getWeight());
    return $menu_link;
  }

}


  /** * @dataProvider providerTestGetWeight * @covers ::getWeight */
  public function testGetWeight($plugin_definition$plugin_id$expected_weight) {
    $this->pluginDefinition = $plugin_definition;
    $this->pluginId = $plugin_id;
    $this->setupLocalTaskDefault();

    $this->assertEquals($expected_weight$this->localTaskBase->getWeight());
  }

  /** * @covers ::getActive * @covers ::setActive */
  public function testActive() {
    $this->setupLocalTaskDefault();

    $this->assertFalse($this->localTaskBase->getActive());
    $this->localTaskBase->setActive();
    

  protected function assertEntity(int $id, string $expected_language, string $expected_label, string $expected_vid, ?string $expected_description = '', ?string $expected_format = NULL, int $expected_weight = 0, array $expected_parents = [], int $expected_field_integer_value = NULL, int $expected_term_reference_tid = NULL): void {
    /** @var \Drupal\taxonomy\TermInterface $entity */
    $entity = Term::load($id);
    $this->assertInstanceOf(TermInterface::class$entity);
    $this->assertSame($expected_language$entity->language()->getId());
    $this->assertSame($expected_label$entity->label());
    $this->assertSame($expected_vid$entity->bundle());
    $this->assertSame($expected_description$entity->getDescription());
    $this->assertSame($expected_format$entity->getFormat());
    $this->assertSame($expected_weight$entity->getWeight());
    $this->assertHierarchy($expected_vid$id$expected_parents);
  }

  /** * Asserts that a term is present in the tree storage, with the right parents. * * @param string $vid * Vocabulary ID. * @param int $tid * ID of the term to check. * @param array $parent_ids * The expected parent term IDs. * * @internal */
protected function assertEntity(string $id, string $title, string $menu, ?string $description, bool $enabled, bool $expanded, array $attributes, string $uri, int $weight): void {
    /** @var \Drupal\menu_link_content\MenuLinkContentInterface $menu_link */
    $menu_link = MenuLinkContent::load($id);
    $this->assertInstanceOf(MenuLinkContentInterface::class$menu_link);
    $this->assertSame($title$menu_link->getTitle());
    $this->assertSame($menu$menu_link->getMenuName());
    $this->assertSame($description$menu_link->getDescription());
    $this->assertSame($enabled$menu_link->isEnabled());
    $this->assertSame($expanded$menu_link->isExpanded());
    $this->assertSame($attributes$menu_link->link->options);
    $this->assertSame($uri$menu_link->link->uri);
    $this->assertSame($weight$menu_link->getWeight());
  }

  /** * Tests migration of menu links. */
  public function testMenuLinks() {
    $this->assertEntity('138', 'Test 1', 'secondary-links', 'Test menu link 1', TRUE, FALSE, ['attributes' => ['title' => 'Test menu link 1'], 'langcode' => 'en'], 'internal:/user/login', -50);
    $this->assertEntity('139', 'Test 2', 'secondary-links', 'Test menu link 2', TRUE, TRUE, ['query' => ['foo' => 'bar'], 'attributes' => ['title' => 'Test menu link 2']], 'internal:/admin', -49);
    $this->assertEntity('140', 'Drupal.org', 'secondary-links', NULL, TRUE, FALSE, ['attributes' => ['title' => '']], 'https://www.drupal.org', -50);

    // Assert that missing title attributes don't stop or break migration.

  public function toArray() {
    return [
      'uuid' => $this->getUuid(),
      'region' => $this->getRegion(),
      'configuration' => $this->getConfiguration(),
      'weight' => $this->getWeight(),
      'additional' => $this->additional,
    ];
  }

  /** * Creates an object from an array representation of the section component. * * Only use this method if you are implementing custom storage for sections. * * @param array $component * An array of section component data in the format returned by ::toArray(). * * @return static * The section component object. */
Home | Imprint | This part of the site doesn't use cookies.