system_region_list example

    $this->moduleInstaller()->install(['module_test'], FALSE);
    $this->assertTrue($this->moduleHandler()->moduleExists('module_test'));

    $themes = $this->themeHandler()->listInfo();
    $this->assertTrue(isset($themes[$name]->info['regions']['test_region']));

    // Legacy assertions.     // @todo Remove once theme initialization/info has been modernized.     // @see https://www.drupal.org/node/2228093     $info = \Drupal::service('extension.list.theme')->getExtensionInfo($name);
    $this->assertTrue(isset($info['regions']['test_region']));
    $regions = system_region_list($name);
    $this->assertTrue(isset($regions['test_region']));
    $theme_list = \Drupal::service('theme_handler')->listInfo();
    $this->assertTrue(isset($theme_list[$name]->info['regions']['test_region']));

    $this->moduleInstaller()->uninstall(['module_test']);
    $this->assertFalse($this->moduleHandler()->moduleExists('module_test'));

    $themes = $this->themeHandler()->listInfo();
    $this->assertFalse(isset($themes[$name]->info['regions']['test_region']));

    // Legacy assertions.
$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);
  }

}
/** * Returns the human-readable list of regions keyed by machine name. * * @param string $theme * The name of the theme. * * @return array * An array of human-readable region names keyed by machine name. */
  protected function getVisibleRegionNames($theme) {
    return system_region_list($theme, REGIONS_VISIBLE);
  }

}


    // Region settings.     $entity_region = $entity->getRegion();
    $region = $entity->isNew() ? $this->getRequest()->query->get('region', $entity_region) : $entity_region;
    $form['region'] = [
      '#type' => 'select',
      '#title' => $this->t('Region'),
      '#description' => $this->t('Select the region where this block should be displayed.'),
      '#default_value' => $region,
      '#required' => TRUE,
      '#options' => system_region_list($form_state->getValue('theme', $theme), REGIONS_VISIBLE),
      '#prefix' => '<div id="edit-block-region-wrapper">',
      '#suffix' => '</div>',
    ];
    $form['#attached']['library'][] = 'block/drupal.block.admin';
    return $form;
  }

  /** * Handles switching the available regions based on the selected theme. */
  public function themeSwitch($form, FormStateInterface $form_state) {
    
return $this->t('The @entity-type %label has been removed from the %region region.', [
      '@entity-type' => $entity->getEntityType()->getSingularLabel(),
      '%label' => $entity->label(),
      '%region' => $regions[$entity->getRegion()],
    ]);
  }

  /** * Wraps system_region_list(). */
  protected function systemRegionList($theme$show = REGIONS_ALL) {
    return system_region_list($theme$show);
  }

}


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

    // Ensure the region is valid to mirror the behavior of block_rebuild().     // This is done primarily for backwards compatibility support of     // \Drupal\block\BlockInterface::BLOCK_REGION_NONE.     $regions = system_region_list($this->theme);
    if (!isset($regions[$this->region]) && $this->status()) {
      $this
        ->setRegion(system_default_region($this->theme))
        ->disable();
    }
  }

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