Skip to content

Instantly share code, notes, and snippets.

@nitriques
Last active August 29, 2015 14:03
Show Gist options
  • Save nitriques/c710cc1838b12c8a1e4a to your computer and use it in GitHub Desktop.
Save nitriques/c710cc1838b12c8a1e4a to your computer and use it in GitHub Desktop.
Creating lot of fields in a Symphony section
<?php
// BOOTSTRAP SYMPHONY
define('DOCROOT', str_replace('/manifest', '', rtrim(dirname(__FILE__), '\\/') ));
define('VERBOSE', 1);
// section id
define('SOURCE', 41);
require_once(DOCROOT . '/symphony/lib/boot/bundle.php');
require_once(DOCROOT . '/symphony/lib/core/class.cacheable.php');
require_once(DOCROOT . '/symphony/lib/core/class.symphony.php');
require_once(DOCROOT . '/symphony/lib/core/class.administration.php');
require_once(DOCROOT . '/symphony/lib/toolkit/class.general.php');
require_once(TOOLKIT . '/class.sectionmanager.php');
require_once(TOOLKIT . '/class.entrymanager.php');
// creates the DB
Administration::instance();
$fieldTypes = array('input','checkbox');
for ($x = 1; $x <= 100; $x++) {
$field = FieldManager::create($fieldTypes[array_rand($fieldTypes)]);
$field->set('label', "Field $x");
$field->set('element_name', "field-$x");
$field->set('location', "main");
$field->set('sortorder', (string)($x - 1));
$field->set('parent_section', SOURCE);
if (!$field->commit()) {
echo "Error while commiting field $x" . PHP_EOL;
} else if (VERBOSE) {
$id = $field->get('id');
echo "Field $x:$id created" . PHP_EOL;
}
}
if (VERBOSE) {
echo PHP_EOL . "All done." . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment