public function configure() { parent::configure(); // We must explicitly limit the fields because otherwise tables with foreign key relationships // to the pages table will extend the form whether it's appropriate or not. If you want to do // those things on behalf of an engine used in some pages, define a form class called // enginemodulenameEngineForm. It will automatically be instantiated with the engine page // as an argument to the constructor, and rendered beneath the main page settings form. // On submit, it will be bound to the parameter name that begins its name format and, if valid, // saved consecutively after the main page settings form. The form will be rendered via // the _renderPageSettingsForm partial in your engine module, which must exist, although it // can be as simple as echo $form. (Your form is passed to the partial as $form.) // // We would use embedded forms if we could. Unfortunately Symfony has unresolved bugs relating // to one-to-many relations in embedded forms. $this->useFields(array('slug', 'template', 'engine', 'archived', 'view_is_secure')); unset($this['author_id'], $this['deleter_id'], $this['Accesses'], $this['created_at'], $this['updated_at'], $this['view_credentials'], $this['edit_credentials'], $this['lft'], $this['rgt'], $this['level']); $this->setWidget('template', new sfWidgetFormSelect(array('choices' => aTools::getTemplates()))); $this->setWidget('engine', new sfWidgetFormSelect(array('choices' => aTools::getEngines()))); // On vs. off makes more sense to end users, but when we first // designed this feature we had an 'archived vs. unarchived' // approach in mind $this->setWidget('archived', new sfWidgetFormChoice(array('expanded' => true, 'choices' => array(false => "Published", true => "Unpublished"), 'default' => false))); if ($this->getObject()->hasChildren()) { $this->setWidget('cascade_archived', new sfWidgetFormInputCheckbox()); $this->setValidator('cascade_archived', new sfValidatorBoolean(array('true_values' => array('true', 't', 'on', '1'), 'false_values' => array('false', 'f', 'off', '0', ' ', '')))); $this->setWidget('cascade_view_is_secure', new sfWidgetFormInputCheckbox()); $this->setValidator('cascade_view_is_secure', new sfValidatorBoolean(array('true_values' => array('true', 't', 'on', '1'), 'false_values' => array('false', 'f', 'off', '0', ' ', '')))); } $this->setWidget('view_is_secure', new sfWidgetFormChoice(array('expanded' => true, 'choices' => array(false => "Public", true => "Login Required"), 'default' => false))); $this->addPrivilegeWidget('edit', 'editors'); $this->addPrivilegeWidget('manage', 'managers'); $this->setValidator('slug', new aValidatorSlug(array('required' => true, 'allow_slashes' => true), array('required' => 'The slug cannot be empty.', 'invalid' => 'The slug must contain only slashes, letters, digits, dashes and underscores. Also, you cannot change a slug to conflict with an existing slug.'))); $this->setValidator('template', new sfValidatorChoice(array('required' => true, 'choices' => array_keys(aTools::getTemplates())))); // Making the empty string one of the choices doesn't seem to be good enough // unless we expressly clear 'required' $this->setValidator('engine', new sfValidatorChoice(array('required' => false, 'choices' => array_keys(aTools::getEngines())))); // The slug of the home page cannot change (chicken and egg problems) if ($this->getObject()->getSlug() === '/') { unset($this['slug']); } else { $this->validatorSchema->setPostValidator(new sfValidatorDoctrineUnique(array('model' => 'aPage', 'column' => 'slug'), array('invalid' => 'There is already a page with that slug.'))); } $this->widgetSchema->setIdFormat('a_settings_%s'); $this->widgetSchema->setNameFormat('settings[%s]'); $this->widgetSchema->setFormFormatterName('list'); $user = sfContext::getInstance()->getUser(); if (!$user->hasCredential('cms_admin')) { unset($this['editors']); unset($this['managers']); unset($this['slug']); } // We changed the form formatter name, so we have to reset the translation catalogue too $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe'); }
/** * Get template choices in the new format, then provide bc with the old format * (one level with no engines specified), and also add entries for any engines * listed in the old way that don't have templates specified in the new way * @return mixed */ public static function getTemplates() { if (sfConfig::get('app_a_get_templates_method')) { $method = sfConfig::get('app_a_get_templates_method'); return call_user_func($method); } $templates = sfConfig::get('app_a_templates', array('a' => array('default' => 'Default Page', 'home' => 'Home Page'))); // Provide bc $newTemplates = $templates; foreach ($templates as $key => $value) { if (!is_array($value)) { $newTemplates['a'][$key] = $value; unset($newTemplates[$key]); } } $templates = $newTemplates; $engines = aTools::getEngines(); foreach ($engines as $name => $label) { if (!strlen($name)) { // Ignore the "template-based" engine option continue; } if (!isset($templates[$name])) { $templates[$name] = array('default' => $label); } } return $templates; }