Skip to content

Loading…

Allow fields to create their own schema XML #6

Merged
merged 1 commit into from

2 participants

@psychoticmeow

Useful for fields that are incompatible with the HTML scraping method, for example the Date Time field. Developers should be encoraged to define this in their custom fields so that the use of displayPublishPanel can be discontinued at some point.

@psychoticmeow psychoticmeow Allow fields to create their own schema XML
Useful for fields that are incompatible with the HTML scraping method, for example the Date Time field. Developers should be encoraged to define this in their custom fields so that the use of displayPublishPanel can be discontinued at some point.
de75a8f
@nickdunn nickdunn merged commit 53c7bd8 into symphonists:master
@nickdunn

Nice idea, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 21, 2012
  1. @psychoticmeow

    Allow fields to create their own schema XML

    psychoticmeow committed
    Useful for fields that are incompatible with the HTML scraping method, for example the Date Time field. Developers should be encoraged to define this in their custom fields so that the use of displayPublishPanel can be discontinued at some point.
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 19 deletions.
  1. +26 −19 data-sources/datasource.section_schema.php
View
45 data-sources/datasource.section_schema.php
@@ -28,9 +28,9 @@ public function settings() {
$settings = array();
$settings[self::getClass()]['section'] = $this->dsParamSECTION;
$settings[self::getClass()]['fields'] = $this->dsParamFIELDS;
-
+
if(is_null($settings[self::getClass()]['fields'])) $settings[self::getClass()]['fields'] = array();
-
+
return $settings;
}
@@ -56,18 +56,18 @@ public function getSourceColumn($handle) {
-------------------------------------------------------------------------*/
public static function buildEditor(XMLElement $wrapper, array &$errors = array(), array $settings = null, $handle = null) {
-
+
Administration::instance()->Page->addScriptToHead(URL . '/extensions/section_schemas/assets/section_schemas.datasource.js', 100);
-
+
if(is_null($settings[self::getClass()]['fields'])) $settings[self::getClass()]['fields'] = array();
-
+
$fieldset = new XMLElement('fieldset');
$fieldset->setAttribute('class', 'settings contextual ' . __CLASS__);
$fieldset->appendChild(new XMLElement('legend', self::getName()));
$group = new XMLElement('div');
$group->setAttribute('class', 'two columns');
-
+
$options = array();
$sections = SectionManager::fetch();
foreach($sections as $section) {
@@ -75,16 +75,16 @@ public static function buildEditor(XMLElement $wrapper, array &$errors = array()
$section->get('handle'), $settings[self::getClass()]['section'] == $section->get('handle'), $section->get('name')
);
}
-
+
$label = Widget::Label(__('Section'));
$label->setAttribute('class', 'column');
$label->appendChild(
Widget::Select('fields[' . self::getClass() . '][section]', $options)
);
$group->appendChild($label);
-
+
foreach($sections as $section) {
-
+
$fields = $section->fetchFields();
$options = array();
foreach($fields as $field) {
@@ -92,25 +92,25 @@ public static function buildEditor(XMLElement $wrapper, array &$errors = array()
$field->get('element_name'), in_array($field->get('element_name'), $settings[self::getClass()]['fields']), $field->get('label') . ' (' . $field->get('type') . ')'
);
}
-
+
$label = Widget::Label(__('Fields'));
$label->setAttribute('class', 'column fields fields-for-' . $section->get('handle'));
$label->appendChild(
Widget::Select('fields[' . self::getClass() . '][fields][]', $options, array('multiple' => 'multiple'))
);
$group->appendChild($label);
-
+
}
$fieldset->appendChild($group);
$wrapper->appendChild($fieldset);
}
-
+
public static function validate(array &$settings, array &$errors) {
return true;
}
-
+
public static function prepare(array $settings, array $params, $template) {
return sprintf($template,
$params['rootelement'],
@@ -167,10 +167,18 @@ public function grab(array $param_pool) {
}
}
+ // Skip fields that have not been selected:
+ if (!in_array($field['element_name'], $this->dsParamFIELDS)) continue;
+
+ // Allow a field to define its own schema XML:
+ if (method_exists($section_field, 'appendFieldSchema')) {
+ $section_field->appendFieldSchema($f);
+ $result->appendChild($f);
+ continue;
+ }
+
// check that we can safely inspect output of displayPublishPanel (some custom fields do not work)
if (in_array($field['type'], self::$_incompatible_publishpanel)) continue;
-
- if (!in_array($field['element_name'], $this->dsParamFIELDS)) continue;
// grab the HTML used in the Publish entry form
$html = new XMLElement('html');
@@ -217,11 +225,11 @@ public function grab(array $param_pool) {
$result->appendChild($f);
}
-
+
return $result;
-
+
}
-
+
function __appendOption($option, &$container, $field) {
$option_element = new XMLElement('option', $option->nodeValue);
@@ -249,4 +257,3 @@ function __appendOption($option, &$container, $field) {
}
return 'SectionSchemaDatasource';
-
Something went wrong with that request. Please try again.