You are here

public function DoubleFieldField::getSettingsFormValidators in Double Field 7.2

Create field settings form validators.

File

tests/double_field_field.inc, line 93
The file contains a class that assists to test Double Field field settings.

Class

DoubleFieldField
Helper class to test Double Field field settings.

Code

public function getSettingsFormValidators() {
  $form_xpath = '//form[@id="field-ui-field-edit-form"]';
  $validators[] = $form_xpath;
  foreach ($this->subfields as $index => $subfield) {
    $prefix = "{$form_xpath}//fieldset[@id='edit-field-settings-{$index}']";
    $text = $index == 'first' ? t('First subfield') : t('Second subfield');
    $validators[] = "{$prefix}//legend//span[text()='{$text}']";

    // Ensure that sufield type is selected.
    $validators[] = "{$prefix}//select[@name='field[settings][{$index}][type]']//option[@value='{$subfield}' and @selected='selected']";

    // Check subwidget related elements.
    switch ($subfield) {
      case 'varchar':
        $value = $this->settings[$index]['maxlength'];
        $validators[] = "{$prefix}//input[@name='field[settings][{$index}][maxlength]' and @value='{$value}']";
        break;
      case 'int':
      case 'float':
        $value = $this->settings[$index]['size'];
        $validators[] = "{$prefix}//select[@name='field[settings][{$index}][size]']//option[@value='{$value}' and @selected='selected']";
        break;
      case 'decimal':
        $value = $this->settings[$index]['precision'];
        $validators[] = "{$prefix}//select[@name='field[settings][{$index}][precision]']//option[@value='{$value}' and @selected='selected']";
        $value = $this->settings[$index]['scale'];
        $validators[] = "{$prefix}//select[@name='field[settings][{$index}][scale]']//option[@value='{$value}' and @selected='selected']";
        break;
    }
  }
  return $validators;
}