/** * Processes the field data * * @return string */ function process() { foreach ($this->field_data as $field => $data) { $this->field_data[$field] = Fieldtype::process_field_data('text', $data); } return $this->field_data; }
/** * Modify the default schema provided by Fieldtype to include a 'sort' field, and integrate that into the primary key. * */ public function getDatabaseSchema(Field $field) { $schema = parent::getDatabaseSchema($field); $schema['sort'] = 'int unsigned NOT NULL'; $schema['keys']['primary'] = 'PRIMARY KEY (pages_id, sort)'; return $schema; }
public function postUp(Schema $schema) { $em = $this->container->get('doctrine.orm.entity_manager'); $wysiwyg = new Fieldtype(); $wysiwyg->setCreatedBy("migration")->setModifiedBy("migration")->setVariableName("wysiwyg")->setName("WYSIWYG"); $wysiwygUploadPath = new FieldSetupOptions(); $wysiwygUploadPath->setCreatedBy("migration")->setModifiedBy("migration")->setName("WYSIWYG upload path")->setLabel("Image upload path (assets/[path])")->setInputType("text")->setVariableName("wysiwygUploadPath")->setFieldType($wysiwyg); $wysiwygOptions = new FieldSetupOptions(); $wysiwygOptions->setCreatedBy("migration")->setModifiedBy("migration")->setName("WYSIWYG setup options")->setLabel("WYSIWYG setup options (js)")->setInputType("textarea")->setVariableName("wysiwygsetupoptions")->setFieldType($wysiwyg); $wysiwygTrans = new FieldSetupOptions(); $wysiwygTrans->setCreatedBy("migration")->setModifiedBy("migration")->setName("WYSIWYG translatable")->setLabel("Is translatable")->setInputType("checkbox")->setVariableName("wysiwygtrans")->setFieldType($wysiwyg); $em->persist($wysiwyg); $em->persist($wysiwygOptions); $em->persist($wysiwygUploadPath); $em->persist($wysiwygTrans); $em->flush(); }
/** * Constructor * * Assign basic properties to this fieldtype, useful in listing available fieldtypes. * Also defines the MySQL column format for fields of this type. */ function __construct() { parent::__construct(); $this->compatibility = array('publish', 'products', 'collections'); $this->enabled = TRUE; $this->fieldtype_name = 'WYSIWYG Textarea'; $this->fieldtype_description = 'A textarea that includes an HTML editor.'; $this->validation_error = ''; $this->db_column = 'TEXT'; }
/** * Constructor * * Assign basic properties to this fieldtype, useful in listing available fieldtypes. * Also defines the MySQL column format for fields of this type. */ function __construct() { parent::__construct(); $this->compatibility = array('publish', 'users', 'products', 'collections', 'forms'); $this->enabled = TRUE; $this->fieldtype_name = 'Select Dropdown'; $this->fieldtype_description = 'Select one of many options in a dropdown list.'; $this->validation_error = ''; $this->db_column = 'VARCHAR(150)'; }
public function control_panel__add_to_head() { if (URL::getCurrent(false) != '/publish' && URL::getCurrent(false) != '/member') { return; } $config = array('max_files' => 1, 'allowed' => array(), 'destination' => 'UPLOAD_PATH', 'browse' => false); $fieldtype = Fieldtype::render_fieldtype('file', 'markituploader', $config, null, null, 'markituploader', 'markituploader'); $template = File::get($this->getAddonLocation() . 'views/modal.html'); return $this->js->inline('Statamic.markituploader = ' . json_encode(Parse::template($template, compact('fieldtype'))) . ';'); }
/** * Constructor * * Assign basic properties to this fieldtype, useful in listing available fieldtypes. * Also defines the MySQL column format for fields of this type. */ function __construct() { parent::__construct(); $this->compatibility = array('publish', 'users', 'products', 'collections', 'forms'); $this->enabled = TRUE; $this->fieldtype_name = 'Text'; $this->fieldtype_description = 'A single line of text.'; $this->validation_error = ''; $this->db_column = 'VARCHAR(250)'; }
/** * Constructor * * Assign basic properties to this fieldtype, useful in listing available fieldtypes. * Also defines the MySQL column format for fields of this type. */ function __construct() { parent::__construct(); $this->compatibility = array('publish', 'users', 'products', 'collections', 'forms'); $this->enabled = TRUE; $this->fieldtype_name = 'Content Relationship'; $this->fieldtype_description = 'Select one or more content items (of any content type) from a list.'; $this->validation_error = ''; $this->db_column = 'TEXT'; }
/** * Constructor * * Assign basic properties to this fieldtype, useful in listing available fieldtypes. * Also defines the MySQL column format for fields of this type. */ function __construct() { parent::__construct(); $this->compatibility = array('publish', 'users', 'products', 'collections', 'forms'); $this->enabled = TRUE; $this->fieldtype_name = 'Multicheckbox Options'; $this->fieldtype_description = 'Check one or many options in a list of checkboxes.'; $this->validation_error = ''; $this->db_column = 'TEXT'; }
/** * Constructor * * Assign basic properties to this fieldtype, useful in listing available fieldtypes. * Also defines the MySQL column format for fields of this type. */ function __construct() { parent::__construct(); $this->compatibility = array('publish', 'users', 'products', 'collections', 'forms'); $this->enabled = TRUE; $this->fieldtype_name = 'Member Relationship'; $this->fieldtype_description = 'Select a member from a list.'; $this->validation_error = ''; $this->db_column = 'INT(11)'; }
/** * Constructor * * Assign basic properties to this fieldtype, useful in listing available fieldtypes. * Also defines the MySQL column format for fields of this type. */ function __construct() { parent::__construct(); $this->compatibility = array('publish', 'users', 'products', 'collections', 'forms'); $this->enabled = TRUE; $this->fieldtype_name = 'Checkbox'; $this->fieldtype_description = 'A single on/off checkbox.'; $this->validation_error = ''; $this->db_column = 'TINYINT(1)'; }
/** * Constructor * * Assign basic properties to this fieldtype, useful in listing available fieldtypes. * Also defines the MySQL column format for fields of this type. */ function __construct() { parent::__construct(); $this->compatibility = array('publish', 'users', 'products', 'collections', 'forms'); $this->enabled = TRUE; $this->fieldtype_name = 'Textarea'; $this->fieldtype_description = 'Multiple lines of text.'; $this->validation_error = ''; $this->db_column = 'TEXT'; }
/** * Constructor * * Assign basic properties to this fieldtype, useful in listing available fieldtypes. * Also defines the MySQL column format for fields of this type. */ function __construct() { parent::__construct(); $this->compatibility = array('publish', 'users', 'products', 'collections', 'forms'); $this->enabled = TRUE; $this->fieldtype_name = 'Date & Time'; $this->fieldtype_description = 'Date with time.'; $this->validation_error = ''; $this->db_column = 'DATETIME'; }
/** * Constructor * * Assign basic properties to this fieldtype, useful in listing available fieldtypes. * Also defines the MySQL column format for fields of this type. */ function __construct() { parent::__construct(); $this->compatibility = array('publish', 'users', 'products', 'collections', 'forms'); $this->enabled = TRUE; $this->fieldtype_name = 'File Upload'; $this->fieldtype_description = 'Upload a file.'; $this->validation_error = ''; $this->db_column = 'VARCHAR(150)'; // configuration $this->upload_directory = setting('path_custom_field_uploads'); // we need to detect file extensions in places $this->CI->load->helper('file_extension'); }
$value['display'] = Localization::fetch('password'); } } // If no display label is set, we'll prettify the fieldname itself $value['display'] = array_get($value, 'display', Slug::prettify($key)); ?> <div class="<?php echo implode($wrapper_classes, ' '); ?> " <?php echo implode($wrapper_attributes, ' '); ?> > <?php print Fieldtype::render_fieldtype($fieldtype, $key, $value, $val, tabindex(), $input_key, null, $error); ?> </div> <?php } ?> </div> <div id="publish-action" class="footer-controls push-down"> <input type="submit" class="btn" value="<?php echo Localization::fetch('save'); ?> " id="publish-submit"> </div>
/** * Get the query that matches a Fieldtype table's data with a given value * * Possible template method: If overridden, children should NOT call this parent method. * * @param DatabaseQuerySelect $query * @param string $table The table name to use * @param string $subfield Name of the field (typically 'data', unless selector explicitly specified another) * @param string $operator The comparison operator * @param mixed $value The value to find * @return DatabaseQuery $query * */ public function getMatchQuery($query, $table, $subfield, $operator, $value) { self::$getMatchQueryCount++; $n = self::$getMatchQueryCount; $field = $query->field; $database = $this->wire('database'); $table = $database->escapeTable($table); if ($subfield === 'count' && (empty($value) || ctype_digit(ltrim("{$value}", '-'))) && in_array($operator, array("=", "!=", ">", "<", ">=", "<="))) { $value = (int) $value; $t = $table . "_" . $n; $c = $database->escapeTable($this->className()) . "_" . $n; $query->select("{$t}.num_{$t} AS num_{$t}"); $query->leftjoin("(" . "SELECT {$c}.pages_id, COUNT({$c}.pages_id) AS num_{$t} " . "FROM " . $database->escapeTable($field->table) . " AS {$c} " . "GROUP BY {$c}.pages_id " . ") {$t} ON {$t}.pages_id=pages.id"); if (in_array($operator, array('<', '<=', '!=')) && $value || in_array($operator, array('>', '>=')) && $value < 0 || in_array($operator, array('=', '>=')) && !$value) { // allow for possible zero values $query->where("(num_{$t}{$operator}{$value} OR num_{$t} IS NULL)"); // QA } else { // non zero values $query->where("num_{$t}{$operator}{$value}"); // QA } // only allow matches using templates with the requested field $sql = 'pages.templates_id IN('; foreach ($field->getTemplates() as $template) { $sql .= (int) $template->id . ','; } $sql = rtrim($sql, ',') . ')'; $query->where($sql); // QA } else { $query = parent::getMatchQuery($query, $table, $subfield, $operator, $value); } return $query; }
/** * Process data after submission * * @return $array */ public function process() { // Process fieldtypes foreach ($this->field_data as $set_index => $set_data) { $set_name = $set_data['type']; $set_fields = array_get($this->settings['sets'][$set_name], 'fields', array()); unset($set_data['type']); foreach ($set_data as $set_field_name => $set_field_data) { $set_field_settings = $set_fields[$set_field_name]; $the_field_type = array_get($set_field_settings, 'type', 'text'); $field_name = $the_field_type == 'grid' ? "{$this->fieldname}:{$set_index}:{$set_field_name}" : $this->fieldname; $this->field_data[$set_index][$set_field_name] = Fieldtype::process_field_data($the_field_type, $set_field_data, $set_field_settings, $field_name); } } // JavaScript will move the fields around. // We just want the indexes to be reset. return array_values($this->field_data); }
public function process() { if (isset($_FILES['page']['name']['yaml'][$this->fieldname])) { $grid_field = $_FILES['page']['name']['yaml'][$this->fieldname]; foreach ($grid_field as $index => $fields) { foreach ($fields as $field => $value) { if (array_get($this->settings['fields'][$field], 'type') === 'file') { if ($value != '') { $file_values = array('name' => $_FILES['page']['name']['yaml'][$this->fieldname][$index][$field], 'type' => $_FILES['page']['type']['yaml'][$this->fieldname][$index][$field], 'tmp_name' => $_FILES['page']['tmp_name']['yaml'][$this->fieldname][$index][$field], 'error' => $_FILES['page']['error']['yaml'][$this->fieldname][$index][$field], 'size' => $_FILES['page']['size']['yaml'][$this->fieldname][$index][$field]); $this->field_data[$index][$field] = Fieldtype::process_field_data('file', $file_values, $this->settings['fields'][$field]); } else { if (isset($this->field_data[$index]["{$field}_remove"])) { $this->field_data[$index][$field] = ''; } else { $this->field_data[$index][$field] = isset($this->field_data[$index][$field]) ? $this->field_data[$index][$field] : ''; } } // unset the remove column if (isset($this->field_data[$index]["{$field}_remove"])) { unset($this->field_data[$index]["{$field}_remove"]); } } } } } foreach ($this->field_data as $row => $column) { foreach ($column as $field => $data) { $the_field_type = array_get($this->settings['fields'][$field], 'type', 'text'); if ($the_field_type !== 'file') { $this->field_data[$row][$field] = Fieldtype::process_field_data($the_field_type, $data); } } } // if $this->field_data doesn't contain real values, make it an empty string for the people if (Helper::isEmptyArray($this->field_data)) { $this->field_data = ""; } return $this->field_data; }
if (isset($settings['type']) && $settings['type'] == 'checkbox' && !isset($form_data['yaml'][$field])) { $form_data['yaml'][$field] = 0; } } /* |-------------------------------------------------------------------------- | Fieldtype Process Method |-------------------------------------------------------------------------- | | Fieldtypes get the opportunity to process their own data. | That happens right here. | */ foreach ($form_data['yaml'] as $field => $value) { if (isset($field_settings[$field]['type'])) { $file_data[$field] = Fieldtype::process_field_data($field_settings[$field]['type'], $value, $field_settings[$field], $field); } else { $file_data[$field] = $value; } } /* |-------------------------------------------------------------------------- | Clean up data |-------------------------------------------------------------------------- | | We make the assumption that all fields INSIDE the fieldset are editable | and all those OUTSIDE should be left alone. So we filter the submission | against the original fieldset and and wipe out empty fields to keep page | variables clean. Not present = null = consistent data types = happy devs. | */
public function process() { foreach ($this->field_data as $row => $column) { foreach ($column as $field => $data) { $settings = $this->settings['fields'][$field]; $the_field_type = array_get($settings, 'type', 'text'); $this->field_data[$row][$field] = Fieldtype::process_field_data($the_field_type, $data, $settings); } } // if $this->field_data doesn't contain real values, make it an empty string for the people if (Helper::isEmptyArray($this->field_data)) { $this->field_data = ""; } return $this->field_data; }
Session::setFlash('member_old_values', $submission); Session::setFlash('member_errors', $errors); $admin_app->redirect($admin_app->request()->getReferrer()); return; } // set variables foreach ($submission as $key => $value) { if ($key == 'password' && $value == '') { continue; } $field_config = array_get($config, $key, array()); // only save values if save_value isn't false if (array_get($field_config, 'save_value', true)) { // fieldtype processing if there's a type if (isset($config[$key]['type'])) { $value = Fieldtype::process_field_data($config[$key]['type'], $value, $config[$key], $key); } $member->set($key, $value); } else { $member->remove($key); } } // save member $member->save(); // REDIRECT $admin_app->flash('success', Localization::fetch('member_saved')); $url = CP_Helper::show_page('members') ? $admin_app->urlFor('members') : $admin_app->urlFor('pages'); $admin_app->redirect($url); }); // GET: MEMBER // --------------------------------------------------------
</b></p> <pre> global: variable: default value - or - variable_name: </pre> <?php } else { ?> <div class="input-block input-<?php echo $type; ?> "> <?php print Fieldtype::render_fieldtype($type, $key, $field, $value, tabindex(), $input_key); ?> </div> <?php } ?> <?php } ?> </div> <div id="publish-action" class="footer-controls push-down"> <input type="submit" class="btn" value="Save & Publish" id="publish-submit"> </div> </form> </div>
public function process() { if (isset($_FILES['page']['name']['yaml'][$this->fieldname])) { $grid_field = $_FILES['page']['name']['yaml'][$this->fieldname]; foreach ($grid_field as $index => $fields) { foreach ($fields as $field => $value) { if (array_get($this->settings['fields'][$field], 'type') === 'file') { if ($value != '') { $file_values = array('name' => $_FILES['page']['name']['yaml'][$this->fieldname][$index][$field], 'type' => $_FILES['page']['type']['yaml'][$this->fieldname][$index][$field], 'tmp_name' => $_FILES['page']['tmp_name']['yaml'][$this->fieldname][$index][$field], 'error' => $_FILES['page']['error']['yaml'][$this->fieldname][$index][$field], 'size' => $_FILES['page']['size']['yaml'][$this->fieldname][$index][$field]); $this->field_data[$index][$field] = Fieldtype::process_field_data('file', $file_values, $this->settings['fields'][$field]); } else { if (isset($this->field_data[$index]["{$field}_remove"])) { $this->field_data[$index][$field] = ''; } else { $this->field_data[$index][$field] = isset($this->field_data[$index][$field]) ? $this->field_data[$index][$field] : ''; } } // unset the remove column if (isset($this->field_data[$index]["{$field}_remove"])) { unset($this->field_data[$index]["{$field}_remove"]); } } } } } foreach ($this->field_data as $row => $column) { foreach ($column as $field => $data) { if (isset($this->settings['fields'][$field]) && $this->settings['fields'][$field]['type'] != 'file') { $this->field_data[$row][$field] = Fieldtype::process_field_data($this->settings['fields'][$field]['type'], $data); } } } return $this->field_data; }