Ejemplo n.º 1
0
 /**
  * Default UserRegisterForm constructor. If you need to disable modules such as captcha, recaptcha, honeypot, mollom, etc., do it here.
  */
 function __construct()
 {
     // Captcha and Honeypot must be disabled for form submission
     //module_disable(array('captcha', 'recaptcha', 'honeypot', 'mollom'), TRUE);
     //cache_clear_all();
     parent::__construct('user_register_form');
 }
Ejemplo n.º 2
0
 /**
  * Default constructor.
  *
  * @param null|int $id
  *   Comment id if a comment edit form is to be loaded and null if comment
  *   add form is to be loaded.
  */
 public function __construct($id)
 {
     if (!user_access('post comments')) {
         $this->setErrors("User is not allowed to post comments.");
         $this->setInitialized(FALSE);
         return;
     }
     $args = func_get_args();
     array_shift($args);
     $nid = array_shift($args);
     $pid = array_shift($args);
     $classname = get_called_class();
     $class = new \ReflectionClass($classname);
     $class_shortname = $class->getShortName();
     $class_fullname = "RedTest\\entities\\Comment\\" . substr($class_shortname, 0, -4);
     $commentObject = new $class_fullname($id, $nid, $pid);
     if (!$commentObject->getInitialized()) {
         $this->setErrors($commentObject->getErrors());
         $this->setInitialized(FALSE);
         return;
     }
     $this->setEntityObject($commentObject);
     $nid = $commentObject->getNidValues();
     $node = node_load($nid);
     if ($node->comment != COMMENT_NODE_OPEN && is_null($id)) {
         $this->setErrors("Node {$nid} does not allow posting of comments.");
         $this->setInitialized(FALSE);
         return;
     }
     $type = Utils::makeSnakeCase(substr($class_shortname, 0, -11));
     parent::__construct('comment_node_' . $type . '_form', (object) array('nid' => $nid, 'pid' => $pid));
 }
Ejemplo n.º 3
0
 /**
  * Default constructor of the node form. You should not be invoking NodeForm
  * directly. Create a form for your content type that extends NodeForm and
  * invoke that. The access level has to be kept public here because access
  * level of parent class has to be match that of child class.
  *
  * @param null|int $nid
  *   Node id if an existing node form is to be loaded. If a new node form is
  *   to be created, then keep it empty.
  */
 public function __construct($nid = NULL)
 {
     $classname = get_called_class();
     $class = new \ReflectionClass($classname);
     $class_shortname = $class->getShortName();
     $class_fullname = "RedTest\\entities\\Node\\" . Utils::makeTitleCase(substr($class_shortname, 0, -4));
     $type = Utils::makeSnakeCase(substr($class_shortname, 0, -4));
     $nodeObject = new $class_fullname($nid);
     $this->setEntityObject($nodeObject);
     if (!is_null($this->getEntityObject()->getEntity())) {
         $this->includeFile('inc', 'node', 'node.pages');
         parent::__construct($type . '_node_form', $this->getEntityObject()->getEntity());
     }
     $this->setInitialized(TRUE);
 }
Ejemplo n.º 4
0
 /**
  * Default constructor of the taxonomy term form. You should not be invoking
  * TaxonomyFormTerm directly. Create a form for your vocabulary that extends
  * TaxonomyFormTerm and invoke that. The access level has to be kept public
  * here because access level of parent class has to be match that of child
  * class.
  *
  * @param null|int $tid
  *   Taxonomy term id if a taxonomy term edit form is to be loaded. If a
  *   taxonomy term add form is to be created, then keep it empty.
  */
 public function __construct($tid = NULL)
 {
     $classname = get_called_class();
     $class = new \ReflectionClass($classname);
     $class_shortname = $class->getShortName();
     $vocabulary_name = Utils::makeSnakeCase(substr($class_shortname, 0, -4));
     if (!is_null($tid) && is_numeric($tid)) {
         // Tid is not null and is numeric.
         $term = taxonomy_term_load($tid);
         if ($term->vocabulary_machine_name == $vocabulary_name) {
             $this->vocabulary = taxonomy_vocabulary_machine_name_load($vocabulary_name);
             $base_path = "RedTest\\entities\\TaxonomyTerm\\";
             $class_fullname = $base_path . substr($class_shortname, 0, -4);
             $termObject = new $class_fullname($tid);
             $this->setEntityObject($termObject);
             $this->includeFile('inc', 'taxonomy', 'taxonomy.admin');
             parent::__construct('taxonomy_form_term', $term, $this->vocabulary);
             $this->setInitialized(TRUE);
             return;
         } else {
             // Vocabulary name of the provided term does not match the class it was called from. Return with a FAIL response.
             $this->setErrors("Vocabulary of the provided term does not match the class it was called from.");
             $this->setInitialized(FALSE);
             return;
         }
     } else {
         // Proper tid is not provided. Create a dummy term object.
         $base_path = "RedTest\\entities\\TaxonomyTerm\\";
         $class_fullname = $base_path . substr($class_shortname, 0, -4);
         $termObject = new $class_fullname();
         $this->setEntityObject($termObject);
     }
     // tid is not provided or is not numeric.
     $this->vocabulary = taxonomy_vocabulary_machine_name_load($vocabulary_name);
     $this->includeFile('inc', 'taxonomy', 'taxonomy.admin');
     parent::__construct('taxonomy_form_term', array(), $this->vocabulary);
     $this->setInitialized(TRUE);
 }