Commit 255f220c authored by Mykola Mashevskyi's avatar Mykola Mashevskyi Committed by Mateu Aguiló Bosch
Browse files

Issue #3305128 by mmv93, tim-diels: Add "weight" property for environment_indicator entity type

parent c8eca018
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -13,6 +13,9 @@ environment_indicator.switcher.*:
    name:
      type: string
      label: 'Name'
    weight:
      type: string
      label: 'Name'
    url:
      type: uri
      label: 'URL'
+3 −0
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ function environment_indicator_page_top(array &$page_top) {
  // Only add the environment indicator switcher if there are environments to
  // switch to.
  if ($items = _environment_indicator_switcher_links()) {
    uasort($items, 'Drupal\Component\Utility\SortArray::sortByWeightElement');
    $page_top['indicator']['switcher'] = [
      '#theme' => 'links',
      '#links' => $items,
@@ -269,6 +270,7 @@ function _environment_indicator_switcher_toolbar_links() {
  if (!$items = _environment_indicator_switcher_links()) {
    return [];
  };
  uasort($items, 'Drupal\Component\Utility\SortArray::sortByWeightElement');
  $menu = [
    '#theme' => 'links__toolbar_shortcuts',
    '#links' => $items,
@@ -307,6 +309,7 @@ function _environment_indicator_switcher_links() {
        'title' => t('Open in: @label', ['@label' => $entity->label()]),
        'url' => Url::fromUri($entity->getUrl() . $current_path),
        'type' => 'link',
        'weight' => $entity->getWeight(),
      ];
    },
    array_filter(
+28 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface;
 *     "description",
 *     "name",
 *     "url",
 *     "weight",
 *     "fg_color",
 *     "bg_color",
 *   }
@@ -67,6 +68,13 @@ class EnvironmentIndicator extends ConfigEntityBase implements ConfigEntityInter
   */
  public $url;

  /**
   * The switchers link weight.
   *
   * @var string
   */
  public $weight;

  /**
   * The color code for the indicator.
   *
@@ -105,6 +113,16 @@ class EnvironmentIndicator extends ConfigEntityBase implements ConfigEntityInter
    return $this->get('url');
  }

  /**
   * Gets the weight.
   *
   * @return string
   *   The weight of switcher environment.
   */
  public function getWeight() {
    return $this->get('weight');
  }

  /**
   * Gets the foreground color.
   *
@@ -145,6 +163,16 @@ class EnvironmentIndicator extends ConfigEntityBase implements ConfigEntityInter
    $this->set('name', $name);
  }

  /**
   * Sets the weight.
   *
   * @param string $weight
   *   The environment link weight.
   */
  public function setWeight($weight) {
    $this->set('weight', $weight);
  }

  /**
   * Sets the URL.
   *
+7 −0
Original line number Diff line number Diff line
@@ -37,6 +37,13 @@ class EnvironmentIndicatorForm extends EntityForm {
      '#description' => $this->t('The hostname you want to switch to.'),
      '#default_value' => $environment_switcher->getUrl(),
    ];

    $form['weight'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Weight'),
      '#default_value' => $environment_switcher->getWeight(),
    ];

    $form['bg_color'] = [
      '#type' => 'color',
      '#title' => $this->t('Background Color'),