setWeight example

/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->section = new Section(
      'layout_onecol',
      [],
      [
        new SectionComponent('existing-uuid', 'some-region', ['id' => 'existing-block-id']),
        (new SectionComponent('20000000-0000-1000-a000-000000000000', 'ordered-region', ['id' => 'second-block-id']))->setWeight(3),
        (new SectionComponent('10000000-0000-1000-a000-000000000000', 'ordered-region', ['id' => 'first-block-id']))->setWeight(2),
      ],
      [
        'bad_judgement' => ['blink_speed' => 'fast', 'spin_direction' => 'clockwise'],
        'hunt_and_peck' => ['delay' => '300ms'],
      ]
    );
  }

  /** * @covers ::__construct * @covers ::setComponent * @covers ::getComponents */


  /** * Appends a component to the end of a region. * * @param \Drupal\layout_builder\SectionComponent $component * The component being appended. * * @return $this */
  public function appendComponent(SectionComponent $component) {
    $component->setWeight($this->getNextHighestWeight($component->getRegion()));
    $this->setComponent($component);
    return $this;
  }

  /** * Returns the next highest weight of the component in a region. * * @param string $region * The region name. * * @return int * A number higher than the highest weight of the component in the region. */
/** * Updates image effect weights. * * @param array $effects * Associative array with effects having effect uuid as keys and array * with effect data as values. */
  protected function updateEffectWeights(array $effects) {
    foreach ($effects as $uuid => $effect_data) {
      if ($this->entity->getEffects()->has($uuid)) {
        $this->entity->getEffect($uuid)->setWeight($effect_data['weight']);
      }
    }
  }

}
    $this->drupalLogin($this->drupalCreateUser([
      'access toolbar',
      'access shortcuts',
      'access content overview',
      'administer content types',
    ]));
    $this->drupalGet(Url::fromRoute('<front>'));
    $shortcuts = $this->cssSelect('#toolbar-item-shortcuts-tray .toolbar-menu a');
    $this->assertEquals('Add content', $shortcuts[0]->getText());
    $this->assertEquals('All content', $shortcuts[1]->getText());
    foreach ($this->set->getShortcuts() as $shortcut) {
      $shortcut->setWeight($shortcut->getWeight() * -1)->save();
    }
    $this->drupalGet(Url::fromRoute('<front>'));
    $shortcuts = $this->cssSelect('#toolbar-item-shortcuts-tray .toolbar-menu a');
    $this->assertEquals('All content', $shortcuts[0]->getText());
    $this->assertEquals('Add content', $shortcuts[1]->getText());
  }

  /** * Tests the 'access shortcuts' permission for shortcut set administration. */
  private function verifyAccessShortcutsPermissionForEditPages() {
    

  public static function fromArray(array $component) {
    return (new static(
      $component['uuid'],
      $component['region'],
      $component['configuration'],
      $component['additional']
    ))->setWeight($component['weight']);
  }

}
$product->setCloseouts($listProduct->isCloseouts());
        $product->setEan($listProduct->getEan());
        $product->setHeight($listProduct->getHeight());
        $product->setKeywords($listProduct->getKeywords());
        $product->setLength($listProduct->getLength());
        $product->setLongDescription($listProduct->getLongDescription());
        $product->setMinStock($listProduct->getMinStock());
        $product->setReleaseDate($listProduct->getReleaseDate());
        $product->setShippingTime($listProduct->getShippingTime());
        $product->setShortDescription($listProduct->getShortDescription());
        $product->setStock($listProduct->getStock());
        $product->setWeight($listProduct->getWeight());
        $product->setWidth($listProduct->getWidth());
        $product->setPriceGroup($listProduct->getPriceGroup());
        $product->setCreatedAt($listProduct->getCreatedAt());
        $product->setUpdatedAt($listProduct->getUpdatedAt());
        $product->setPriceRules($listProduct->getPriceRules());
        $product->setCheapestPriceRule($listProduct->getCheapestPriceRule());
        $product->setManufacturerNumber($listProduct->getManufacturerNumber());
        $product->setMetaTitle($listProduct->getMetaTitle());
        $product->setTemplate($listProduct->getTemplate());
        $product->setHasConfigurator($listProduct->hasConfigurator());
        $product->setSales($listProduct->getSales());
        
/** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_state->cleanValues();

    // The image effect configuration is stored in the 'data' key in the form,     // pass that through for submission.     $this->imageEffect->submitConfigurationForm($form['data'], SubformState::createForSubform($form['data']$form$form_state));

    $this->imageEffect->setWeight($form_state->getValue('weight'));
    if (!$this->imageEffect->getUuid()) {
      $this->imageStyle->addImageEffect($this->imageEffect->getConfiguration());
    }
    $this->imageStyle->save();

    $this->messenger()->addStatus($this->t('The image effect was successfully applied.'));
    $form_state->setRedirectUrl($this->imageStyle->toUrl('edit-form'));
  }

  /** * Converts an image effect ID into an object. * * @param string $image_effect * The image effect ID. * * @return \Drupal\image\ImageEffectInterface * The image effect object. */
$tree = $this->storageController->loadTree($vocabulary->id(), 0, NULL, TRUE);

    if (empty($tree)) {
      return;
    }

    // Build a list of all terms that need to be updated on previous pages.     $weight = 0;
    $term = $tree[0];
    while ($term->id() != $form['#first_tid']) {
      if ($term->parents[0] == 0 && $term->getWeight() != $weight) {
        $term->setWeight($weight);
        $changed_terms[$term->id()] = $term;
      }
      $weight++;
      $term = $tree[$weight];
    }

    // Renumber the current page weights and assign any new parents.     $level_weights = [];
    foreach ($form_state->getValue('terms') as $tid => $values) {
      if (isset($form['terms'][$tid]['#term'])) {
        $term = $form['terms'][$tid]['#term'];
        
$form['actions']['submit']['#value'] = $this->t('Add effect');

    return $form;
  }

  /** * {@inheritdoc} */
  protected function prepareImageEffect($image_effect) {
    $image_effect = $this->effectManager->createInstance($image_effect);
    // Set the initial weight so this effect comes last.     $image_effect->setWeight(count($this->imageStyle->getEffects()));
    return $image_effect;
  }

}
'#submit' => ['::submitForm', '::save'],
      ],
    ];
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    foreach ($this->entity->getShortcuts() as $shortcut) {
      $weight = $form_state->getValue(['shortcuts', 'links', $shortcut->id(), 'weight']);
      $shortcut->setWeight($weight);
      $shortcut->save();
    }
    $this->messenger()->addStatus($this->t('The shortcut set has been updated.'));
  }

}


  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $blocks = $form_state->getValue('blocks');
    $entities = $this->storage->loadMultiple(array_keys($blocks));
    /** @var \Drupal\block\BlockInterface[] $entities */
    foreach ($entities as $entity_id => $entity) {
      $entity_values = $form_state->getValue(['blocks', $entity_id]);
      $entity->setWeight($entity_values['weight']);
      $entity->setRegion($entity_values['region']);
      $entity->save();
    }
    $this->messenger->addStatus($this->t('The block settings have been updated.'));
  }

  /** * Wraps system_region_list(). */
  protected function systemRegionList($theme$show = REGIONS_ALL) {
    return system_region_list($theme$show);
  }
$delta = $this->getSelectedDelta($form_state);
    $original_section = $this->sectionStorage->getSection($this->delta);
    $component = $original_section->getComponent($this->uuid);
    $section = $this->sectionStorage->getSection($delta);
    if ($delta !== $this->delta) {
      // Remove component from old section and add it to the new section.       $original_section->removeComponent($this->uuid);
      $section->insertComponent(0, $component);
    }
    $component->setRegion($region);
    foreach ($form_state->getValue('components') as $uuid => $component_info) {
      $section->getComponent($uuid)->setWeight($component_info['weight']);
    }
    $this->layoutTempstore->set($this->sectionStorage);
  }

  /** * Ajax callback for the region select element. * * @param array $form * The form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. * * @return array * The components wrapper render array. */
if ($data['__product_changetime']) {
            $product->setUpdatedAt(
                new DateTime($data['__product_changetime'])
            );
        }

        $product->setAdditional($data['__variant_additionaltext']);
        $product->setEan($data['__variant_ean']);
        $product->setHeight((float) $data['__variant_height']);
        $product->setLength((float) $data['__variant_length']);
        $product->setMinStock((int) $data['__variant_stockmin']);
        $product->setWeight((float) $data['__variant_weight']);
        $product->setWidth((float) $data['__variant_width']);

        $customerGroups = explode('|', $data['__product_blocked_customer_groups'] ?? '');
        $customerGroups = array_filter($customerGroups);
        $product->setBlockedCustomerGroupIds($customerGroups);
        $product->setHasAvailableVariant($data['__product_has_available_variants'] > 0);

        $product->setFallbackPriceCount($data['__product_fallback_price_count']);
        if (\array_key_exists('__product_custom_price_count', $data)) {
            $product->setCustomerPriceCount($data['__product_custom_price_count']);
        } else {
            
$this->entityRepository = $this->container->get('entity.repository');

    $this->setUpCurrentUser();

    $this->installEntitySchema('entity_test');
    $this->installEntitySchema('entity_test_rev');
    $this->installEntitySchema('entity_test_mul');
    $this->installEntitySchema('entity_test_mulrev');

    $this->installConfig(['system', 'language']);
    ConfigurableLanguage::createFromLangcode('it')
      ->setWeight(1)
      ->save();
    ConfigurableLanguage::createFromLangcode('ro')
      ->setWeight(2)
      ->save();

    $this->container->get('state')->set('entity_test.translation', TRUE);
    $this->container->get('entity_type.bundle.info')->clearCachedBundles();
  }

  /** * Tests retrieving active variants. * * @covers ::getActive * @covers ::getActiveMultiple */
$entities = $controller->loadMultiple($shortcut_ids);
      $controller->delete($entities);
    }
  }

  /** * {@inheritdoc} */
  public function resetLinkWeights() {
    $weight = -50;
    foreach ($this->getShortcuts() as $shortcut) {
      $shortcut->setWeight(++$weight);
      $shortcut->save();
    }

    return $this;
  }

  /** * {@inheritdoc} */
  public function getShortcuts() {
    $shortcuts = \Drupal::entityTypeManager()->getStorage('shortcut')->loadByProperties(['shortcut_set' => $this->id()]);
    
Home | Imprint | This part of the site doesn't use cookies.