You are here

class Mp3playerAddForm in MP3 Player 8

Implements an Mp3playerAddForm form.

Hierarchy

Expanded class hierarchy of Mp3playerAddForm

1 string reference to 'Mp3playerAddForm'
mp3player.routing.yml in ./mp3player.routing.yml
mp3player.routing.yml

File

src/Form/Mp3playerAddForm.php, line 18
Contains \Drupal\mp3player\Form\ExampleForm.

Namespace

Drupal\mp3player\Form
View source
class Mp3playerAddForm extends FormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'mp3player_player_form';
  }
  public function buildForm(array $form, FormStateInterface $form_state, $pid = NULL) {
    $player = Mp3playerController::mp3player_players($pid);
    if (!$pid) {
      $player = $player[1];
      $player['pid'] = '';
      $player['name'] = '';
    }
    else {
      $player = $player[$pid];
    }
    $form['namegroup'] = array(
      '#type' => 'fieldset',
      '#title' => t('Player Name'),
      '#weight' => -2,
      '#collapsible' => FALSE,
      '#collapsed' => FALSE,
    );
    $form['namegroup']['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Name'),
      '#default_value' => Html::escape($player['name']),
      '#required' => TRUE,
      '#size' => '20',
      '#description' => t('Unique name of player. Please use alphanumeric characters, and underscores (_).'),
    );
    if ($player['name'] == 'Default') {
      $form['namegroup']['name']['#disabled'] = TRUE;
    }
    if ($pid) {
      $form['pid'] = array(
        '#type' => 'hidden',
        '#value' => $pid,
      );
    }
    $form['options'] = array(
      '#type' => 'fieldset',
      '#title' => t('Player Options'),
      '#weight' => -1,
      '#collapsible' => FALSE,
      '#collapsed' => FALSE,
    );
    $form['options']['autostart'] = array(
      '#type' => 'select',
      '#title' => t('Auto-start'),
      '#default_value' => $player['autostart'],
      '#options' => array(
        'no' => t('No'),
        'yes' => t('Yes'),
      ),
      '#description' => t('If yes, player starts automatically.'),
    );
    $form['options']['loopaudio'] = array(
      '#type' => 'select',
      '#title' => t('Loop Audio'),
      '#default_value' => $player['loopaudio'],
      '#options' => array(
        'no' => t('No'),
        'yes' => t('Yes'),
      ),
      '#description' => t('If yes, player loops audio.'),
    );
    $form['options']['animation'] = array(
      '#type' => 'select',
      '#title' => t('Animate'),
      '#default_value' => $player['animation'],
      '#options' => array(
        'no' => t('No'),
        'yes' => t('Yes'),
      ),
      '#description' => t('If no, player is always open.'),
    );
    $form['options']['remaining'] = array(
      '#type' => 'select',
      '#title' => t('Time Remaining'),
      '#default_value' => $player['remaining'],
      '#options' => array(
        'no' => t('No'),
        'yes' => t('Yes'),
      ),
      '#description' => t('If yes, shows remaining track time rather than elapsed time.'),
    );
    $form['options']['noinfo'] = array(
      '#type' => 'select',
      '#title' => t("Don't display information"),
      '#default_value' => $player['noinfo'],
      '#options' => array(
        'no' => t('No'),
        'yes' => t('Yes'),
      ),
      '#description' => t('If yes, disables the track information display.'),
    );
    $form['options']['initialvolume'] = array(
      '#type' => 'textfield',
      '#title' => t('Initial Volume'),
      '#default_value' => $player['initialvolume'],
      '#default_value' => Html::escape($player['initialvolume']),
      '#required' => TRUE,
      '#size' => '10',
      '#description' => t('Initial volume level (from 0 to 100).'),
    );
    $form['options']['buffer'] = array(
      '#type' => 'textfield',
      '#title' => t('Buffer Time'),
      '#default_value' => $player['buffer'],
      '#default_value' => Html::escape($player['buffer']),
      '#required' => TRUE,
      '#size' => '10',
      '#description' => t('Buffering time in seconds.'),
    );
    $form['options']['encode'] = array(
      '#type' => 'select',
      '#title' => t('Encode'),
      '#default_value' => $player['encode'],
      '#options' => array(
        'no' => t('No'),
        'yes' => t('Yes'),
      ),
      '#description' => t('Indicates that the mp3 file urls are encoded.'),
    );
    $form['options']['checkpolicy'] = array(
      '#type' => 'select',
      '#title' => t('Check Policy'),
      '#default_value' => $player['checkpolicy'],
      '#options' => array(
        'no' => t('No'),
        'yes' => t('Yes'),
      ),
      '#description' => t('Tells Flash to look for a policy file when loading mp3 files (this allows Flash to read ID3 tags from files hosted on a different domain.'),
    );
    $form['options']['rtl'] = array(
      '#type' => 'select',
      '#title' => t('Text Right-to-Left'),
      '#default_value' => $player['rtl'],
      '#options' => array(
        'no' => t('No'),
        'yes' => t('Yes'),
      ),
      '#description' => t('Switches the layout to RTL (right to left) for Hebrew and Arabic languages.'),
    );
    $form['options']['width'] = array(
      '#type' => 'textfield',
      '#title' => t('Player Width'),
      '#default_value' => $player['width'],
      '#default_value' => Html::escape($player['width']),
      '#required' => TRUE,
      '#size' => '10',
      '#description' => t('Width of the player. e.g. 290 (290 pixels) or 100%.'),
    );
    $form['colours'] = array(
      '#type' => 'fieldset',
      '#title' => t('Player Colour Scheme'),
      '#weight' => 0,
      '#collapsible' => FALSE,
      '#collapsed' => FALSE,
    );
    $form['colours']['transbg'] = array(
      '#type' => 'fieldset',
      '#title' => 'Player Background',
      '#collapsible' => FALSE,
      '#collapsed' => FALSE,
    );
    $form['colours']['transbg']['transparentpagebg'] = array(
      '#type' => 'select',
      '#title' => t('Transparent Player Background'),
      '#default_value' => $player['transparentpagebg'],
      '#options' => array(
        'no' => t('No'),
        'yes' => t('Yes'),
      ),
      '#description' => t('If yes, the player background is transparent (matches the page background).'),
    );
    $form['colours']['transbg']['pagebg'] = array(
      '#type' => 'textfield',
      '#title' => t('Player Background Colour'),
      '#default_value' => Html::escape($player['pagebg']),
      '#required' => FALSE,
      '#size' => '10',
      '#field_prefix' => '#',
      '#description' => t("Player background colour (set it to your page background when transparentbg is set to 'no')."),
    );
    $form['colours']['bg'] = array(
      '#type' => 'textfield',
      '#title' => t('Background'),
      '#default_value' => $player['bg'],
      '#default_value' => Html::escape($player['bg']),
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
    );
    $form['colours']['leftbg'] = array(
      '#type' => 'textfield',
      '#title' => t('Left Background'),
      '#default_value' => $player['leftbg'],
      '#default_value' => Html::escape($player['leftbg']),
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
      '#description' => t('Speaker icon/Volume control background.'),
    );
    $form['colours']['lefticon'] = array(
      '#type' => 'textfield',
      '#title' => t('Speaker Icon'),
      '#default_value' => $player['lefticon'],
      '#default_value' => Html::escape($player['lefticon']),
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
    );
    $form['colours']['voltrack'] = array(
      '#type' => 'textfield',
      '#title' => t('Volume Track Background'),
      '#default_value' => $player['voltrack'],
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
    );
    $form['colours']['volslider'] = array(
      '#type' => 'textfield',
      '#title' => t('Volume Track Slider'),
      '#default_value' => $player['volslider'],
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
    );
    $form['colours']['rightbg'] = array(
      '#type' => 'textfield',
      '#title' => t('Right Background'),
      '#default_value' => $player['rightbg'],
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
      '#description' => t('Play/Pause button background.'),
    );
    $form['colours']['rightbghover'] = array(
      '#type' => 'textfield',
      '#title' => t('Right Background Hover'),
      '#default_value' => $player['rightbghover'],
      '#default_value' => Html::escape($player['rightbghover']),
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
      '#description' => t('Play/Pause button background (hover state).'),
    );
    $form['colours']['righticon'] = array(
      '#type' => 'textfield',
      '#title' => t('Play/Pause Icon'),
      '#default_value' => $player['righticon'],
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
    );
    $form['colours']['righticonhover'] = array(
      '#type' => 'textfield',
      '#title' => t('Play/Pause Icon (hover state)'),
      '#default_value' => Html::escape($player['righticonhover']),
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
    );
    $form['colours']['loader'] = array(
      '#type' => 'textfield',
      '#title' => t('Loading Bar'),
      '#default_value' => Html::escape($player['loader']),
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
    );
    $form['colours']['track'] = array(
      '#type' => 'textfield',
      '#title' => t('Track Backgrounds'),
      '#default_value' => Html::escape($player['track']),
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
      '#description' => t('Loading/Progress bar track background.'),
    );
    $form['colours']['tracker'] = array(
      '#type' => 'textfield',
      '#title' => t('Progress Track'),
      '#default_value' => Html::escape($player['tracker']),
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
    );
    $form['colours']['border'] = array(
      '#type' => 'textfield',
      '#title' => t('Progress Track Border'),
      '#default_value' => Html::escape($player['border']),
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
    );
    $form['colours']['skip'] = array(
      '#type' => 'textfield',
      '#title' => t('Previous/Next Buttons'),
      '#default_value' => Html::escape($player['skip']),
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
    );
    $form['colours']['text'] = array(
      '#type' => 'textfield',
      '#title' => t('Text'),
      '#default_value' => Html::escape($player['text']),
      '#required' => TRUE,
      '#size' => '10',
      '#field_prefix' => '#',
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save changes to player'),
    );
    return $form;
  }

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

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state
      ->getValues();
    if (isset($values['pid'])) {
      $keys = array(
        'pid' => $values['pid'],
      );
    }
    else {
      $keys = array(
        'name' => $values['name'],
      );
    }
    \Drupal::database()
      ->merge('mp3player_players')
      ->key($keys)
      ->fields(array(
      'name' => $values['name'],
      'autostart' => $values['autostart'],
      'loopaudio' => $values['loopaudio'],
      'animation' => $values['animation'],
      'remaining' => $values['remaining'],
      'noinfo' => $values['noinfo'],
      'initialvolume' => $values['initialvolume'],
      'buffer' => $values['buffer'],
      'encode' => $values['encode'],
      'checkpolicy' => $values['checkpolicy'],
      'rtl' => $values['rtl'],
      'width' => $values['width'],
      'transparentpagebg' => $values['transparentpagebg'],
      'pagebg' => $values['pagebg'],
      'bg' => $values['bg'],
      'leftbg' => $values['leftbg'],
      'lefticon' => $values['lefticon'],
      'voltrack' => $values['voltrack'],
      'volslider' => $values['volslider'],
      'rightbg' => $values['rightbg'],
      'rightbghover' => $values['rightbghover'],
      'righticon' => $values['righticon'],
      'righticonhover' => $values['righticonhover'],
      'loader' => $values['loader'],
      'track' => $values['track'],
      'tracker' => $values['tracker'],
      'border' => $values['border'],
      'skip' => $values['skip'],
      'text' => $values['text'],
    ))
      ->execute();
    $form_state
      ->setRedirect('mp3player.player_list');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create 87
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.
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.
Mp3playerAddForm::buildForm public function Form constructor. Overrides FormInterface::buildForm
Mp3playerAddForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
Mp3playerAddForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
Mp3playerAddForm::validateForm public function Form validation handler. Overrides FormBase::validateForm
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.