You are here

class GetId3ConfigForm in getID3() 8

Hierarchy

Expanded class hierarchy of GetId3ConfigForm

1 string reference to 'GetId3ConfigForm'
getid3.routing.yml in ./getid3.routing.yml
getid3.routing.yml

File

src/Form/GetId3ConfigForm.php, line 14
Contains \Drupal\getid3\Form\GetId3ConfigForm.

Namespace

Drupal\getid3\Form
View source
class GetId3ConfigForm extends ConfigFormBase {

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

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $path = getid3_get_path();
    $form['getid3_path'] = array(
      '#type' => 'textfield',
      '#title' => $this
        ->t('Path'),
      '#default_value' => $path,
      '#description' => $this
        ->t('The location where getID3() is installed. Relative paths are from the Drupal root directory.'),
    );
    $form['getid3_path']['#after_build'][] = array(
      get_class($this),
      'afterBuild',
    );
    if ($version = getid3_get_version()) {
      $form['getid3_version'] = array(
        '#type' => 'item',
        '#title' => $this
          ->t('Version'),
        '#markup' => '<pre>' . SafeMarkup::checkPlain($version) . '</pre>',
        '#description' => $this
          ->t("If you're seeing this it indicates that the getID3 library was found."),
      );

      // Check for existence of the 'demos' folder, contained in the getID3
      // library. The contents of this folder create a potential securtiy hole,
      // so we recommend that the user delete it.
      $getid3_demos_path = $path . '/../demos';
      if (file_exists($getid3_demos_path)) {
        drupal_set_message($this
          ->t("Your getID3 library is insecure! The demos distributed with getID3 contains code which creates a huge security hole. Remove the demos directory (%path) from beneath Drupal's directory.", array(
          '%path' => realpath($getid3_demos_path),
        )), 'error');
      }
    }
    $show_warnings = $this
      ->config('getid3.settings')
      ->get('getid3_show_warnings');
    if (empty($show_warnings)) {
      $show_warnings = FALSE;
    }
    $form['getid3_show_warnings'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t("Display Warnings"),
      '#default_value' => $show_warnings,
      '#description' => $this
        ->t("Check this to display the warning messages from the getID3 library when reading and writing ID3 tags. Generally it's a good idea to leave this unchecked, getID3 reports warnings for several trivial problems and the warnings can be confusing to users. This setting can be useful when debugging problems with the ID3 tags."),
    );
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);

    // Save the new value.
    $this
      ->config('getid3.settings')
      ->set('path', $form_state
      ->getValue('getid3_path'))
      ->set('getid3_show_warnings', $form_state
      ->getValue('getid3_show_warnings'))
      ->save();
  }

  /**
   * Verifies that getid3 is in the directory specified by the form element.
   *
   * Checks that the directory in $form_element exists and contains files named
   * 'getid3.php' and 'write.php'. If validation fails, the form element is
   * flagged with an error.
   *
   * @param array $form_element
   *   The form element containing the name of the directory to check.
   *
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   * @return array
   */
  public static function afterBuild(array $form_element, FormStateInterface $form_state) {
    $path = $form_state
      ->getValue('getid3_path');
    if (!is_dir($path) || !(file_exists($path . '/getid3.php') && file_exists($path . '/write.php'))) {
      drupal_set_message(t('The getID3 files <em>getid3.php</em> and <em>write.php</em> could not be found in the %path directory.', array(
        '%path' => $path,
      )), 'error');
    }
    return $form_element;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 13
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 11
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.
GetId3ConfigForm::afterBuild public static function Verifies that getid3 is in the directory specified by the form element.
GetId3ConfigForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
GetId3ConfigForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
GetId3ConfigForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
GetId3ConfigForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
GetId3ConfigForm::validateForm public function Form validation handler. Overrides FormBase::validateForm
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.
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.