You are here

class FooterSettingsForm in Open Social 10.3.x

Same name and namespace in other branches
  1. 10.0.x modules/social_features/social_footer/src/Form/FooterSettingsForm.php \Drupal\social_footer\Form\FooterSettingsForm
  2. 10.1.x modules/social_features/social_footer/src/Form/FooterSettingsForm.php \Drupal\social_footer\Form\FooterSettingsForm
  3. 10.2.x modules/social_features/social_footer/src/Form/FooterSettingsForm.php \Drupal\social_footer\Form\FooterSettingsForm

Creates a form for configuring footer block.

Hierarchy

Expanded class hierarchy of FooterSettingsForm

1 string reference to 'FooterSettingsForm'
social_footer.routing.yml in modules/social_features/social_footer/social_footer.routing.yml
modules/social_features/social_footer/social_footer.routing.yml

File

modules/social_features/social_footer/src/Form/FooterSettingsForm.php, line 13

Namespace

Drupal\social_footer\Form
View source
class FooterSettingsForm extends FormBase {

  /**
   * The file storage.
   *
   * @var \Drupal\file\FileStorageInterface
   */
  protected $fileStorage;

  /**
   * Creates a FooterSettingsForm instance.
   *
   * @param \Drupal\file\FileStorageInterface $file_storage
   *   The file storage.
   */
  public function __construct(FileStorageInterface $file_storage) {
    $this->fileStorage = $file_storage;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity_type.manager')
      ->getStorage('file'));
  }

  /**
   * {@inheritDoc}
   */
  public function getFormId() {
    return 'social_footer_config_form';
  }

  /**
   * {@inheritDoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $block = self::configFactory()
      ->get('block.block.socialblue_footer_powered');
    if ($block) {
      $settings = $block
        ->get('settings');
    }
    $default_scheme = self::config('system.file')
      ->get('default_scheme');
    $form['logo'] = [
      '#type' => 'managed_file',
      '#title' => $this
        ->t('Logo'),
      '#upload_location' => $default_scheme . '://',
      '#upload_validators' => [
        'file_validate_is_image' => [],
      ],
      '#default_value' => [
        $settings['logo'],
      ] ?? NULL,
    ];
    $form['text'] = [
      '#type' => 'text_format',
      '#title' => $this
        ->t('Text'),
      '#default_value' => $settings['text']['value'] ?? NULL,
      '#format' => $settings['text']['format'] ?? 'basic_html',
    ];
    $form['link'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Link') ?? NULL,
    ];
    $form['link']['url'] = [
      '#type' => 'url',
      '#title' => $this
        ->t('URL'),
      '#default_value' => $settings['link']['url'] ?? NULL,
    ];
    $form['link']['title'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Title'),
      '#default_value' => $settings['link']['title'] ?? NULL,
    ];
    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Save configuration'),
      '#button_type' => 'primary',
    ];
    return $form;
  }

  /**
   * {@inheritDoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $logo = '';
    $values = $form_state
      ->getValues();
    if ($values['logo'] = $form_state
      ->getValue('logo')) {

      /** @var \Drupal\file\FileInterface $file */
      $file = $this->fileStorage
        ->load($logo = $values['logo'][0]);
      $file
        ->setPermanent();
      $file
        ->save();
    }
    $block = self::configFactory()
      ->getEditable('block.block.socialblue_footer_powered');
    if ($block) {
      $settings = $block
        ->get('settings');
      $settings['logo'] = $logo;
      $settings['text'] = $values['text'];
      $settings['link']['url'] = $values['url'];
      $settings['link']['title'] = $values['title'];
      $block
        ->set('settings', $settings)
        ->save();
    }
    $this
      ->messenger()
      ->addStatus(t('Your footer settings have been updated'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FooterSettingsForm::$fileStorage protected property The file storage.
FooterSettingsForm::buildForm public function Form constructor. Overrides FormInterface::buildForm
FooterSettingsForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
FooterSettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
FooterSettingsForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
FooterSettingsForm::__construct public function Creates a FooterSettingsForm instance.
FormBase::$configFactory protected property The config factory. 3
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 3
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.
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 72
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. 27
MessengerTrait::messenger public function Gets the messenger. 27
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. 4
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.