You are here

class HostingDeployForm in Aegir Deploy 7.3

@file The HostingDeployForm class.

Hierarchy

Expanded class hierarchy of HostingDeployForm

File

includes/HostingDeployForm.inc, line 6
The HostingDeployForm class.

View source
class HostingDeployForm extends HostingForm {
  public function __construct(&$form, &$form_state, &$node = FALSE) {
    parent::__construct($form, $form_state, $node);
    if ($this->node->type == 'platform') {
      $this->platform = new HostingDeployNode($this->node);
    }
  }
  public function alter() {
    $this
      ->makeFieldsetsIntoRadios('field_deployment_strategy', $this
      ->getStrategyLabels());
    $this
      ->addDefaultStrategyOption();
    $this
      ->setStrategy();
    $readonly = isset($this->node->platform_status) && $this->node->platform_status != HOSTING_PLATFORM_QUEUED && !empty($this->node->field_deployment_strategy);
    if ($readonly) {
      $this
        ->makeFieldReadOnly('field_deployment_strategy');
    }
    $this
      ->addGitHelp();

    // TODO: Add a validator to ensure required fields for a given strategy are
    // provided. Add a submit handler to clear out values from other
    // strategies' fields?
  }

  /**
   * Add default option and make it first.
   */
  protected function addDefaultStrategyOption() {
    $default = 'none';
    $options = $this->form['field_deployment_strategy'][$this
      ->language()]['#options'];
    $this->form['field_deployment_strategy'][$this
      ->language()]['#options'] = [
      $default => $options[$default],
    ] + $options;
  }
  protected function setStrategy() {
    if ($this
      ->isANewNode()) {
      $this
        ->setFormDefaultValue('field_deployment_strategy', 'none');
    }
    else {
      $this
        ->setFormDefaultValue('field_deployment_strategy', $this
        ->determineExistingStrategy());
    }
  }
  protected function determineExistingStrategy() {
    if (!empty($this->platform
      ->getFieldValue('field_deployment_strategy'))) {
      return $this->platform
        ->getFieldValue('field_deployment_strategy');
    }
    else {
      return $this
        ->guessStrategy();
    }
  }
  protected function guessStrategy() {
    foreach ($this
      ->getStrategyRequiredFields() as $strategy => $fields) {
      foreach ($fields as $field) {
        if (!empty($this->platform
          ->getFieldValue($field))) {
          return $strategy;
        }
      }
    }
    return 'none';
  }
  protected function addGitHelp() {
    if (module_exists('hosting_git')) {
      $this->form['git']['#description'] = t('You may deploy and manage this platform from a Git repository. This strategy is appropriate for development scenarios or when each such platform will only host a single site.');
      if (module_exists('hosting_platform_git')) {
        $this->form['git']['#description'] .= t(' It differs from <em>Deploy from Git repository</em> in that, once deployed, platforms can be updated or otherwise changed via Git.');
        $this->form['platform_git']['#description'] .= t(' It differs from <em>Manage with Git</em> in that, once deployed, platforms are treated as immutable.');
      }
    }
  }
  protected static function getStrategies() {
    $strategies = module_invoke_all('platform_deploy_strategies');
    drupal_alter('platform_deploy_strategies', $strategies);
    return $strategies;
  }
  public static function getStrategyLabels() {
    foreach (self::getStrategies() as $name => $strategy) {
      $strategies[$name] = $strategy['label'];
    }
    return $strategies;
  }
  public function getStrategyRequiredFields() {
    foreach ($this
      ->getStrategies() as $name => $strategy) {
      $strategies[$name] = $strategy['required_fields'];
    }
    return $strategies;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HostingDeployForm::addDefaultStrategyOption protected function Add default option and make it first.
HostingDeployForm::addGitHelp protected function
HostingDeployForm::alter public function
HostingDeployForm::determineExistingStrategy protected function
HostingDeployForm::getStrategies protected static function
HostingDeployForm::getStrategyLabels public static function
HostingDeployForm::getStrategyRequiredFields public function
HostingDeployForm::guessStrategy protected function
HostingDeployForm::setStrategy protected function
HostingDeployForm::__construct public function Contructor method. Overrides HostingForm::__construct
HostingForm::$form public property
HostingForm::$form_state public property
HostingForm::$node public property
HostingForm::addSubmitHandler public function Register a form submit handler.
HostingForm::addValidateHandler public function Register a form validate handler.
HostingForm::closeOverlay function Properly close dialogs, or re-direct back to source node, depending on whether overlay.module is enabled.
HostingForm::disableField protected function Hide a form field.
HostingForm::error public function
HostingForm::getFormStateValue public function
HostingForm::isAField protected function
HostingForm::isANewNode protected function Determine whether we're creating a new node, or editing an existing one.
HostingForm::language protected function
HostingForm::makeFieldReadOnly public function Render a form field un-editable.
HostingForm::makeFieldsetsIntoRadios protected function
HostingForm::moveFieldsIntoFieldset protected function
HostingForm::setFieldListOptions protected function
HostingForm::setFormDefaultValue protected function
HostingForm::setFormStateValue public function