API Moving placeholder variable to EditableFormField (#581)

This commit is contained in:
3Dgoo 2017-04-28 18:01:51 +09:30 committed by Damian Mooyman
parent a94f0e35aa
commit 457a8a7557
13 changed files with 102 additions and 62 deletions

View File

@ -14,6 +14,8 @@ class EditableDateField extends EditableFormField
private static $plural_name = 'Date Fields'; private static $plural_name = 'Date Fields';
private static $has_placeholder = true;
private static $db = array( private static $db = array(
'DefaultToToday' => 'Boolean' // From customsettings 'DefaultToToday' => 'Boolean' // From customsettings
); );

23
code/model/editableformfields/EditableEmailField.php Executable file → Normal file
View File

@ -14,24 +14,7 @@ class EditableEmailField extends EditableFormField
private static $plural_name = 'Email Fields'; private static $plural_name = 'Email Fields';
private static $db = array( private static $has_placeholder = true;
'Placeholder' => 'Varchar(255)'
);
public function getCMSFields()
{
$this->beforeUpdateCMSFields(function ($fields) {
$fields->addFieldToTab(
'Root.Main',
TextField::create(
'Placeholder',
_t('EditableTextField.PLACEHOLDER', 'Placeholder')
)
);
});
return parent::getCMSFields();
}
public function getSetsOwnError() public function getSetsOwnError()
{ {
@ -59,9 +42,5 @@ class EditableEmailField extends EditableFormField
parent::updateFormField($field); parent::updateFormField($field);
$field->setAttribute('data-rule-email', true); $field->setAttribute('data-rule-email', true);
if ($this->Placeholder) {
$field->setAttribute('placeholder', $this->Placeholder);
}
} }
} }

View File

@ -61,6 +61,13 @@ class EditableFormField extends DataObject
*/ */
public static $allowed_css = array(); public static $allowed_css = array();
/**
* Set this to true to enable placeholder field for any given class
* @config
* @var bool
*/
private static $has_placeholder = false;
/** /**
* @config * @config
* @var array * @var array
@ -89,6 +96,7 @@ class EditableFormField extends DataObject
"RightTitle" => "Varchar(255)", // from CustomSettings "RightTitle" => "Varchar(255)", // from CustomSettings
"ShowOnLoad" => "Boolean(1)", // from CustomSettings "ShowOnLoad" => "Boolean(1)", // from CustomSettings
"ShowInSummary" => "Boolean", "ShowInSummary" => "Boolean",
"Placeholder" => "Varchar(255)",
'DisplayRulesConjunction' => 'Enum("And,Or","Or")', 'DisplayRulesConjunction' => 'Enum("And,Or","Or")',
); );
@ -249,6 +257,17 @@ class EditableFormField extends DataObject
$fields->addFieldsToTab('Root.DisplayRules', $displayFields); $fields->addFieldsToTab('Root.DisplayRules', $displayFields);
} }
// Placeholder
if ($this->config()->has_placeholder) {
$fields->addFieldToTab(
'Root.Main',
TextField::create(
'Placeholder',
_t('EditableFormField.PLACEHOLDER', 'Placeholder')
)
);
}
$this->extend('updateCMSFields', $fields); $this->extend('updateCMSFields', $fields);
return $fields; return $fields;
@ -827,6 +846,11 @@ class EditableFormField extends DataObject
if ($this->ExtraClass) { if ($this->ExtraClass) {
$field->addExtraClass($this->ExtraClass); $field->addExtraClass($this->ExtraClass);
} }
// if this field has a placeholder
if ($this->Placeholder) {
$field->setAttribute('placeholder', $this->Placeholder);
}
} }
/** /**

0
code/model/editableformfields/EditableFormHeading.php Executable file → Normal file
View File

View File

@ -14,10 +14,11 @@ class EditableNumericField extends EditableFormField
private static $plural_name = 'Numeric Fields'; private static $plural_name = 'Numeric Fields';
private static $has_placeholder = true;
private static $db = array( private static $db = array(
'MinValue' => 'Int', 'MinValue' => 'Int',
'MaxValue' => 'Int', 'MaxValue' => 'Int'
'Placeholder' => 'Varchar(255)'
); );
public function getSetsOwnError() public function getSetsOwnError()
@ -25,21 +26,6 @@ class EditableNumericField extends EditableFormField
return true; return true;
} }
public function getCMSFields()
{
$this->beforeUpdateCMSFields(function ($fields) {
$fields->addFieldToTab(
'Root.Main',
TextField::create(
'Placeholder',
_t('EditableTextField.PLACEHOLDER', 'Placeholder')
)
);
});
return parent::getCMSFields();
}
/** /**
* @return NumericField * @return NumericField
*/ */
@ -85,9 +71,5 @@ class EditableNumericField extends EditableFormField
if ($this->MaxValue) { if ($this->MaxValue) {
$field->setAttribute('data-rule-max', $this->MaxValue); $field->setAttribute('data-rule-max', $this->MaxValue);
} }
if ($this->Placeholder) {
$field->setAttribute('placeholder', $this->Placeholder);
}
} }
} }

15
code/model/editableformfields/EditableTextField.php Executable file → Normal file
View File

@ -14,6 +14,8 @@ class EditableTextField extends EditableFormField
private static $plural_name = 'Text Fields'; private static $plural_name = 'Text Fields';
private static $has_placeholder = true;
private static $autocomplete_options = array( private static $autocomplete_options = array(
'off' => 'Off', 'off' => 'Off',
'on' => 'On', 'on' => 'On',
@ -50,7 +52,6 @@ class EditableTextField extends EditableFormField
'MinLength' => 'Int', 'MinLength' => 'Int',
'MaxLength' => 'Int', 'MaxLength' => 'Int',
'Rows' => 'Int(1)', 'Rows' => 'Int(1)',
'Placeholder' => 'Varchar(255)',
'Autocomplete' => 'Varchar(255)' 'Autocomplete' => 'Varchar(255)'
); );
@ -72,14 +73,6 @@ class EditableTextField extends EditableFormField
)) ))
); );
$fields->addFieldToTab(
'Root.Main',
TextField::create(
'Placeholder',
_t('EditableTextField.PLACEHOLDER', 'Placeholder')
)
);
$fields->addFieldToTab( $fields->addFieldToTab(
'Root.Main', 'Root.Main',
DropdownField::create( DropdownField::create(
@ -159,10 +152,6 @@ class EditableTextField extends EditableFormField
$field->setAttribute('data-rule-maxlength', intval($this->MaxLength)); $field->setAttribute('data-rule-maxlength', intval($this->MaxLength));
} }
if ($this->Placeholder) {
$field->setAttribute('placeholder', $this->Placeholder);
}
if ($this->Autocomplete) { if ($this->Autocomplete) {
$field->setAttribute('autocomplete', $this->Autocomplete); $field->setAttribute('autocomplete', $this->Autocomplete);
} }

View File

@ -131,6 +131,7 @@ class UserFormsUpgradeService
// - MinLength (EditableTextField) // - MinLength (EditableTextField)
// - MaxLength (EditableTextField) // - MaxLength (EditableTextField)
// - Rows (EditableTextField) // - Rows (EditableTextField)
// - Placeholder (EditableTextField / EditableEmailField / EditableNumericField)
$customSettings = $field->CustomSettings $customSettings = $field->CustomSettings
? unserialize($field->CustomSettings) ? unserialize($field->CustomSettings)
@ -142,6 +143,11 @@ class UserFormsUpgradeService
} }
$field->migrateSettings($customSettings); $field->migrateSettings($customSettings);
if ($field->config()->has_placeholder) {
$this->migratePlaceholder($field, $field->ClassName);
}
$field->write(); $field->write();
} }
@ -224,4 +230,62 @@ class UserFormsUpgradeService
{ {
return $this->quiet; return $this->quiet;
} }
/**
* Migrate Placeholder data from field specific table to the EditableFormField table
*
* @param EditableFormField $field
* @param string $tableName
*/
private function migratePlaceholder($field, $tableName)
{
// Migrate Placeholder setting from $tableName table to EditableFormField table
if ($field->Placeholder) {
return;
}
// Check if draft table exists
if (!DB::get_schema()->hasTable($tableName)) {
// Check if _obsolete_ draft table exists
$tableName = '_obsolete_' . $tableName;
if (!DB::get_schema()->hasTable($tableName)) {
return;
}
}
// Check if old Placeholder column exists
if (!DB::get_schema()->hasField($tableName, 'Placeholder')) {
return;
}
// Fetch existing draft Placeholder value
$query = "SELECT \"Placeholder\" FROM \"$tableName\" WHERE \"ID\" = '$field->ID'";
$draftPlaceholder = DB::query($query)->value();
if (!$draftPlaceholder) {
return;
}
// Update draft Placeholder value
DB::prepared_query(
"UPDATE \"EditableFormField\" SET \"Placeholder\" = ? WHERE \"ID\" = ?",
array($draftPlaceholder, $field->ID)
);
$livePlaceholder = $draftPlaceholder;
// Check if live table exists
$tableName = $tableName . '_Live';
if (DB::get_schema()->hasTable($tableName)) {
// Fetch existing live Placeholder value
$query = "SELECT \"Placeholder\" FROM \"$tableName\" WHERE \"ID\" = '" . $field->ID . "'";
$livePlaceholder = DB::query($query)->value();
if (!$livePlaceholder) {
$livePlaceholder = $draftPlaceholder;
}
}
// Update live Placeholder value
DB::prepared_query(
"UPDATE \"EditableFormField_Live\" SET \"Placeholder\" = ? WHERE \"ID\" = ?",
array($draftPlaceholder, $field->ID)
);
}
} }

View File

@ -64,6 +64,7 @@ de_DE:
NOTBLANK: 'Nicht leer' NOTBLANK: 'Nicht leer'
NOTVALUE: 'Kein Wert' NOTVALUE: 'Kein Wert'
OPTIONS: Optionen OPTIONS: Optionen
PLACEHOLDER: Platzhalter
PLURALNAME: 'Editierbare Formularfelder' PLURALNAME: 'Editierbare Formularfelder'
REQUIRED: 'Pflichtfeld?' REQUIRED: 'Pflichtfeld?'
RIGHTTITLE: 'Titel rechts' RIGHTTITLE: 'Titel rechts'
@ -111,7 +112,6 @@ de_DE:
AUTOCOMPLETE: 'Automatisch vervollständigen' AUTOCOMPLETE: 'Automatisch vervollständigen'
AUTOCOMPLETE_DESCRIPTION: 'Unterstützte Browser versuchen, dieses Feld automatisch mit den Benutzerinformationen zu füllen, verwenden, um den gefüllten Wert festzulegen' AUTOCOMPLETE_DESCRIPTION: 'Unterstützte Browser versuchen, dieses Feld automatisch mit den Benutzerinformationen zu füllen, verwenden, um den gefüllten Wert festzulegen'
NUMBERROWS: 'Anzahl der Zeilen' NUMBERROWS: 'Anzahl der Zeilen'
PLACEHOLDER: Platzhalter
PLURALNAME: Textfelder PLURALNAME: Textfelder
SINGULARNAME: Textfeld SINGULARNAME: Textfeld
TEXTLENGTH: Textlänge TEXTLENGTH: Textlänge

View File

@ -83,6 +83,7 @@ en:
NOTBLANK: 'Not Blank' NOTBLANK: 'Not Blank'
NOTVALUE: 'Not Value' NOTVALUE: 'Not Value'
OPTIONS: Options OPTIONS: Options
PLACEHOLDER: Placeholder
PLURALNAME: 'Editable Form Fields' PLURALNAME: 'Editable Form Fields'
REQUIRED: 'Is this field Required?' REQUIRED: 'Is this field Required?'
REQUIRED_DESCRIPTION: 'Please note that conditional fields can''t be required' REQUIRED_DESCRIPTION: 'Please note that conditional fields can''t be required'
@ -144,7 +145,6 @@ en:
AUTOCOMPLETE_DESCRIPTION: 'Supported browsers will attempt to populate this field automatically with the users information, use to set the value populated' AUTOCOMPLETE_DESCRIPTION: 'Supported browsers will attempt to populate this field automatically with the users information, use to set the value populated'
NUMBERROWS: 'Number of rows' NUMBERROWS: 'Number of rows'
NUMBERROWS_DESCRIPTION: 'Fields with more than one row will be generated as a textarea' NUMBERROWS_DESCRIPTION: 'Fields with more than one row will be generated as a textarea'
PLACEHOLDER: Placeholder
PLURALNAME: 'Text Fields' PLURALNAME: 'Text Fields'
RANGE_TO: to RANGE_TO: to
SINGULARNAME: 'Text Field' SINGULARNAME: 'Text Field'

View File

@ -83,6 +83,7 @@ eo:
NOTBLANK: 'Ne vaka' NOTBLANK: 'Ne vaka'
NOTVALUE: 'Ne valoro' NOTVALUE: 'Ne valoro'
OPTIONS: Agordoj OPTIONS: Agordoj
PLACEHOLDER: Lokokupilo
PLURALNAME: 'Redakteblaj formularaj kampoj' PLURALNAME: 'Redakteblaj formularaj kampoj'
REQUIRED: 'Ĉu ĉi tiu kampo estas nepra?' REQUIRED: 'Ĉu ĉi tiu kampo estas nepra?'
REQUIRED_DESCRIPTION: 'Bonvolu noti ke kondiĉaj kampoj ne povas esti nepraj' REQUIRED_DESCRIPTION: 'Bonvolu noti ke kondiĉaj kampoj ne povas esti nepraj'
@ -142,7 +143,6 @@ eo:
EditableTextField: EditableTextField:
NUMBERROWS: 'Nombro da vicoj' NUMBERROWS: 'Nombro da vicoj'
NUMBERROWS_DESCRIPTION: 'Kampoj kun pli ol unu vico generiĝos kiel tekstareo' NUMBERROWS_DESCRIPTION: 'Kampoj kun pli ol unu vico generiĝos kiel tekstareo'
PLACEHOLDER: Lokokupilo
PLURALNAME: 'Tekstaj kampoj' PLURALNAME: 'Tekstaj kampoj'
RANGE_TO: al RANGE_TO: al
SINGULARNAME: 'Teksta kampo' SINGULARNAME: 'Teksta kampo'

View File

@ -83,6 +83,7 @@ fi_FI:
NOTBLANK: 'Ei ole tyhjä' NOTBLANK: 'Ei ole tyhjä'
NOTVALUE: 'Ei ole sama kuin' NOTVALUE: 'Ei ole sama kuin'
OPTIONS: Valinnat OPTIONS: Valinnat
PLACEHOLDER: Opastusteksti
PLURALNAME: 'Muokattavat lomakekentät' PLURALNAME: 'Muokattavat lomakekentät'
REQUIRED: 'Onko tämä kenttä pakollinen?' REQUIRED: 'Onko tämä kenttä pakollinen?'
REQUIRED_DESCRIPTION: 'Huomioithan, että ehdolliset kentät eivät voi olla pakollisia' REQUIRED_DESCRIPTION: 'Huomioithan, että ehdolliset kentät eivät voi olla pakollisia'
@ -142,7 +143,6 @@ fi_FI:
EditableTextField: EditableTextField:
NUMBERROWS: 'Rivien määrä' NUMBERROWS: 'Rivien määrä'
NUMBERROWS_DESCRIPTION: 'Kenttät, joissa on enemmän kuin yksi rivi, luodaan tekstialueena.' NUMBERROWS_DESCRIPTION: 'Kenttät, joissa on enemmän kuin yksi rivi, luodaan tekstialueena.'
PLACEHOLDER: Opastusteksti
PLURALNAME: Tekstikentät PLURALNAME: Tekstikentät
RANGE_TO: RANGE_TO:
SINGULARNAME: Tekstikenttä SINGULARNAME: Tekstikenttä

View File

@ -83,6 +83,7 @@ it:
NOTBLANK: 'Non vuoto' NOTBLANK: 'Non vuoto'
NOTVALUE: 'Non valore' NOTVALUE: 'Non valore'
OPTIONS: Opzioni OPTIONS: Opzioni
PLACEHOLDER: Segnaposto
PLURALNAME: 'Campi modulo modificabili' PLURALNAME: 'Campi modulo modificabili'
REQUIRED: 'Questo campo è obbligatorio?' REQUIRED: 'Questo campo è obbligatorio?'
REQUIRED_DESCRIPTION: 'Prego nota che i campi condizionali non possono essere obbligatori' REQUIRED_DESCRIPTION: 'Prego nota che i campi condizionali non possono essere obbligatori'
@ -144,7 +145,6 @@ it:
AUTOCOMPLETE_DESCRIPTION: 'I browser supportati cercheranno di popolare automaticamente questo campo con l'informazione agli utenti, usare per impostare il valore popolata' AUTOCOMPLETE_DESCRIPTION: 'I browser supportati cercheranno di popolare automaticamente questo campo con l'informazione agli utenti, usare per impostare il valore popolata'
NUMBERROWS: 'Numero di righe' NUMBERROWS: 'Numero di righe'
NUMBERROWS_DESCRIPTION: 'Campi con più di una riga verranno generati come area testo' NUMBERROWS_DESCRIPTION: 'Campi con più di una riga verranno generati come area testo'
PLACEHOLDER: Segnaposto
PLURALNAME: 'Campi testo' PLURALNAME: 'Campi testo'
RANGE_TO: a RANGE_TO: a
SINGULARNAME: 'Campo testo' SINGULARNAME: 'Campo testo'

View File

@ -82,6 +82,7 @@ sk:
NOTBLANK: Vyplnené NOTBLANK: Vyplnené
NOTVALUE: 'Nie zadanú hodnotu' NOTVALUE: 'Nie zadanú hodnotu'
OPTIONS: Voľba/možnosť OPTIONS: Voľba/možnosť
PLACEHOLDER: 'Zástupná/Ukážková hodnota (placeholder)'
PLURALNAME: 'Formulárové polia' PLURALNAME: 'Formulárové polia'
REQUIRED: 'Je pole povinné/vyžadované?' REQUIRED: 'Je pole povinné/vyžadované?'
REQUIRED_DESCRIPTION: 'Všimnite si prosím, že podmienené polia nemôžu byť vyžadované.' REQUIRED_DESCRIPTION: 'Všimnite si prosím, že podmienené polia nemôžu byť vyžadované.'
@ -138,7 +139,6 @@ sk:
EditableTextField: EditableTextField:
NUMBERROWS: 'Počet riadkov' NUMBERROWS: 'Počet riadkov'
NUMBERROWS_DESCRIPTION: 'Políčka s viac ako jedným riadkom sú generované ako textarea.' NUMBERROWS_DESCRIPTION: 'Políčka s viac ako jedným riadkom sú generované ako textarea.'
PLACEHOLDER: 'Zástupná/Ukážková hodnota (placeholder)'
PLURALNAME: 'Textové polia' PLURALNAME: 'Textové polia'
RANGE_TO: do RANGE_TO: do
SINGULARNAME: 'Textové pole' SINGULARNAME: 'Textové pole'