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');
 }
Exemplo n.º 2
0
 /**
  * DOCUMENT ME
  */
 public function configure()
 {
     parent::configure();
     $manage = $this->getObject()->isNew() ? true : $this->getObject()->userHasPrivilege('manage');
     $user = sfContext::getInstance()->getUser();
     // $page->setArchived(!sfConfig::get('app_a_default_published', sfConfig::get('app_a_default_on', true)));
     // 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.
     $fields = array('slug', 'archived');
     if ($user->hasCredential('cms_admin')) {
         $fields[] = 'edit_admin_lock';
     }
     $this->useFields($fields);
     $object = $this->getObject();
     // The states we really have now are:
     // Public
     // Login required, with various settings plus a boolean for "guest" access
     // Admin only (for which we have added view_admin_lock)
     // The problem is that right now, public and "guest" are distinguished by a single boolean.
     // It's a pain to turn that into an enumeration.
     // So we need an additional "view_guest" boolean consulted when "view_is_secure" is true, and
     // that new boolean should default to true.
     // In 2.0 we'll probably clean these flags up a bit.
     $choices = array('public' => 'Public', 'login' => 'Login Required', 'admin' => 'Admins Only');
     if (!$user->hasCredential('cms_admin')) {
         // You can't stop yourself and your peers from viewing a page
         unset($choices['admin']);
     }
     $default = 'public';
     if ($object->view_admin_lock) {
         $default = 'admin';
     } elseif ($object->view_is_secure) {
         $default = 'login';
     }
     if ($manage) {
         $this->setWidget('view_options', new sfWidgetFormChoice(array('choices' => $choices, 'expanded' => true, 'default' => $default)));
         $this->setValidator('view_options', new sfValidatorChoice(array('choices' => array_keys($choices), 'required' => true)));
         if ($this->getObject()->hasChildren(false)) {
             $this->setWidget('view_options_apply_to_subpages', new sfWidgetFormInputCheckbox(array('label' => 'Apply to Subpages')));
             $this->setValidator('view_options_apply_to_subpages', new sfValidatorBoolean(array('true_values' => array('true', 't', 'on', '1'), 'false_values' => array('false', 'f', 'off', '0', ' ', ''))));
         }
         $this->setWidget('view_individuals', new sfWidgetFormInputHidden(array('default' => $this->getViewIndividualsJSON())));
         $this->setValidator('view_individuals', new sfValidatorCallback(array('callback' => array($this, 'validateViewIndividuals'), 'required' => true)));
         $this->setWidget('view_groups', new sfWidgetFormInputHidden(array('default' => $this->getViewGroupsJSON())));
         $this->setValidator('view_groups', new sfValidatorCallback(array('callback' => array($this, 'validateViewGroups'), 'required' => true)));
     }
     // Changed the name so Doctrine doesn't get uppity
     $engine = $object->engine;
     $template = $object->template;
     if (!strlen($object->template)) {
         $object->template = 'default';
     }
     if (!is_null($object->engine)) {
         $joinedTemplateName = $object->engine . ':' . $object->template;
     } else {
         $joinedTemplateName = 'a' . ':' . $object->template;
     }
     $choices = aTools::getTemplateChoices();
     $this->setWidget('joinedtemplate', new sfWidgetFormSelect(array('choices' => $choices, 'default' => $joinedTemplateName)));
     $this->setValidator('joinedtemplate', new sfValidatorChoice(array('required' => true, 'choices' => array_keys($choices))));
     // Published vs. Unpublished 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(false)) {
         $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', ' ', ''))));
     }
     // Tags
     $options['default'] = implode(', ', $this->getObject()->getTags());
     // added a space after the comma for readability
     if (sfConfig::get('app_a_all_tags', true)) {
         $options['all-tags'] = PluginTagTable::getAllTagNameWithCount();
     } else {
         sfContext::getInstance()->getConfiguration()->loadHelpers('Url');
         $options['typeahead-url'] = url_for('taggableComplete/complete');
     }
     $options['popular-tags'] = PluginTagTable::getPopulars(null, array('sort_by_popularity' => true), false, 10);
     $options['commit-selector'] = '#' . ($this->getObject()->isNew() ? 'a-create-page' : 'a-page-settings') . '-submit';
     $options['tags-label'] = '';
     // class tag-input enabled for typeahead support
     $this->setWidget('tags', new pkWidgetFormJQueryTaggable($options, array('class' => 'tags-input')));
     $this->setValidator('tags', new sfValidatorString(array('required' => false)));
     // Meta Description
     // Call the widget real_meta_description to avoid conflicts with the automatic behavior
     // of Doctrine forms (which will call setMetaDescription before the page is saved, something
     // that newAreaVersion does not support)
     $metaDescription = $this->getObject()->getMetaDescription();
     $this->setWidget('real_meta_description', new sfWidgetFormTextArea(array('default' => html_entity_decode($metaDescription, ENT_COMPAT, 'UTF-8'))));
     $this->setValidator('real_meta_description', new sfValidatorString(array('required' => false)));
     $privilegePage = $this->getObject();
     if ($privilegePage->isNew()) {
         $privilegePage = $this->parent;
     }
     if ($user->hasCredential('cms_admin')) {
         $this->setWidget('edit_individuals', new sfWidgetFormInputHidden(array('default' => $this->getEditIndividualsJSON())));
         $this->setValidator('edit_individuals', new sfValidatorCallback(array('callback' => array($this, 'validateEditIndividuals'), 'required' => true)));
         $this->setWidget('edit_groups', new sfWidgetFormInputHidden(array('default' => $this->getEditGroupsJSON())));
         $this->setValidator('edit_groups', new sfValidatorCallback(array('callback' => array($this, 'validateEditGroups'), 'required' => true)));
     }
     // If you can delete the page, you can change the slug
     if ($manage) {
         $this->setValidator('slug', new aValidatorSlug(array('required' => true, 'allow_slashes' => true, 'require_leading_slash' => true), array('required' => 'The permalink cannot be empty.', 'invalid' => 'The permalink must contain only slashes, letters, digits, dashes and underscores. There must be a leading slash. Also, you cannot change a permalink to conflict with an existing permalink.')));
         $this->setWidget('slug', new sfWidgetFormInputText());
     }
     // Named 'realtitle' to avoid excessively magic Doctrine form behavior.
     // Specifically, updateObject() will automatically call setTitle() if there
     // is such a method and a widget named 'title', and we don't want that to
     // happen until after the page is saved so we can store it in a slot
     $this->setValidator('realtitle', new sfValidatorString(array('required' => true), array('required' => 'The title cannot be empty.')));
     $title = $this->getObject()->getTitle();
     $this->setWidget('realtitle', new sfWidgetFormInputText(array('default' => html_entity_decode($this->getObject()->getTitle(), ENT_COMPAT, 'UTF-8'))));
     // 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');
     // We changed the form formatter name, so we have to reset the translation catalogue too
     $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe');
 }