You are here

class TagcloudsAdminPage in TagCloud 8

Same name and namespace in other branches
  1. 2.0.x src/Form/TagcloudsAdminPage.php \Drupal\tagclouds\Form\TagcloudsAdminPage
  2. 1.0.x src/Form/TagcloudsAdminPage.php \Drupal\tagclouds\Form\TagcloudsAdminPage

Configure site information settings for this site.

Hierarchy

Expanded class hierarchy of TagcloudsAdminPage

1 string reference to 'TagcloudsAdminPage'
tagclouds.routing.yml in ./tagclouds.routing.yml
tagclouds.routing.yml

File

src/Form/TagcloudsAdminPage.php, line 14

Namespace

Drupal\tagclouds\Form
View source
class TagcloudsAdminPage extends ConfigFormBase {

  /**
   * The language manager.
   *
   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
   */
  protected $languageManager;

  /**
   * Constructs a \Drupal\system\ConfigFormBase object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The factory for configuration objects.
   */
  public function __construct(ConfigFactoryInterface $config_factory, LanguageManagerInterface $language_manager) {
    parent::__construct($config_factory);
    $this->languageManager = $language_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.factory'), $container
      ->get('language_manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'tagclouds_settings';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('tagclouds.settings');
    $options = [
      'title,asc' => $this
        ->t('by title, ascending'),
      'title,desc' => $this
        ->t('by title, descending'),
      'count,asc' => $this
        ->t('by count, ascending'),
      'count,desc' => $this
        ->t('by count, descending'),
      'random,none' => $this
        ->t('random'),
    ];
    $sort_order = $config
      ->get('sort_order');
    $form['sort_order'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Tagclouds sort order'),
      '#options' => $options,
      '#default_value' => !empty($sort_order) ? $sort_order : 'title,asc',
      '#description' => $this
        ->t('Determines the sort order of the tags on the freetagging page.'),
    ];
    $options_display = [
      'style' => $this
        ->t('Display Tags with Style'),
      'count' => $this
        ->t('Display Tags with Count'),
    ];
    $display_type = $config
      ->get('display_type');
    $form['display_type'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Tagclouds Display Type'),
      '#options' => $options_display,
      '#default_value' => !empty($display_type) ? $display_type : 'style',
      '#description' => $this
        ->t('Determines the style of the page.'),
    ];
    $form['display_node_link'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Link term to node when only one content is tagged'),
      '#default_value' => $config
        ->get('display_node_link'),
      '#description' => $this
        ->t('When there is only one content tagged with a certain term, link that term to this node instead of the term list page.'),
    ];
    $page_amount = $config
      ->get('page_amount');
    $form['page_amount'] = [
      '#type' => 'textfield',
      '#size' => 5,
      '#title' => $this
        ->t('Amount of tags on the pages'),
      '#default_value' => is_numeric($page_amount) ? $page_amount : 60,
      '#description' => $this
        ->t("The amount of tags that will show up in a cloud on the\n        pages. Enter '0' to display all tags. Amount of tags in blocks must be\n        configured in the block settings of the various cloud blocks."),
    ];
    $levels = $config
      ->get('levels');
    $form['levels'] = [
      '#type' => 'textfield',
      '#size' => 5,
      '#title' => $this
        ->t('Number of levels'),
      '#default_value' => is_numeric($levels) ? $levels : 6,
      '#description' => $this
        ->t('The number of levels between the least popular
        tags and the most popular ones. Different levels will be assigned a different
        class to be themed in tagclouds.css'),
    ];
    $lang = $this->languageManager
      ->getLanguages();
    if (count($lang) > 1) {
      $form['language_separation'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Separation of Tags per language'),
        '#default_value' => $config
          ->get('language_separation'),
        '#description' => $this
          ->t('If you have more than one language installed this setting would allow you to separate the tags for each language.'),
      ];
    }
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this
      ->config('tagclouds.settings')
      ->set('sort_order', $form_state
      ->getValue('sort_order'))
      ->set('display_type', $form_state
      ->getValue('display_type'))
      ->set('display_node_link', $form_state
      ->getValue('display_node_link'))
      ->set('page_amount', $form_state
      ->getValue('page_amount'))
      ->set('levels', $form_state
      ->getValue('levels'));
    if ($form_state
      ->hasValue('language_separation')) {
      $this
        ->config('tagclouds.settings')
        ->set('language_separation', $form_state
        ->getValue('language_separation'));
    }
    $this
      ->config('tagclouds.settings')
      ->save();
    parent::submitForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  function getEditableConfigNames() {
    return [
      'tagclouds.settings',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TagcloudsAdminPage::$languageManager protected property The language manager.
TagcloudsAdminPage::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
TagcloudsAdminPage::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
TagcloudsAdminPage::getEditableConfigNames function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
TagcloudsAdminPage::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
TagcloudsAdminPage::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
TagcloudsAdminPage::__construct public function Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase::__construct
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.