protected function getDefaultHref($label) { $href = $this->app->normalizeName($label, ''); if ($label[0] == ';') { $label = substr($label, 1); $href = ';' . $href; } return $href; }
/** * Adds field in form. * * @param AbstractView|array|string $type * @param AbstractView|array|string $options * @param string $caption * @param string $attr Deprecated argument * * @return Form_Field */ public function addField($type, $options = null, $caption = null, $attr = null) { $insert_into = $this->layout ?: $this; if (is_object($type) && $type instanceof AbstractView && !$type instanceof Form_Field) { // using callback on a sub-view $insert_into = $type; list(, $type, $options, $caption, $attr) = func_get_args(); } if ($options === null) { $options = $type; $type = 'Line'; } if (is_array($options)) { $name = isset($options['name']) ? $options['name'] : null; } else { $name = $options; // backward compatibility } $name = preg_replace('|[^a-z0-9-_]|i', '_', $name); if ($caption === null) { $caption = ucwords(str_replace('_', ' ', $name)); } /* normalzie name and put name back in options array */ $name = $this->app->normalizeName($name); if (is_array($options)) { $options['name'] = $name; } else { $options = array('name' => $name); } $map = array('dropdown' => 'DropDown', 'checkboxlist' => 'CheckboxList', 'hidden' => 'Hidden', 'text' => 'Text', 'line' => 'Line', 'upload' => 'Upload', 'radio' => 'Radio', 'checkbox' => 'Checkbox', 'password' => 'Password', 'timepicker' => 'TimePicker'); $key = strtolower($type); $class = array_key_exists($key, $map) ? $map[$key] : $type; $class = $this->app->normalizeClassName($class, 'Form_Field'); if ($insert_into === $this) { $template = $this->template->cloneRegion('form_line'); $field = $this->add($class, $options, null, $template); } else { if ($insert_into->template->hasTag($name)) { $this->template->cloneRegion('field_input'); $options['show_input_only'] = true; $field = $insert_into->add($class, $options, $name); } else { $template = $this->template->cloneRegion('form_line'); $field = $insert_into->add($class, $options, null, $template); } // Keep Reference, for $form->getElement(). $this->elements[$options['name']] = $field; } /** @type Form_Field $field */ $field->setCaption($caption); $field->setForm($this); $field->template->trySet('field_type', strtolower($type)); if ($attr) { if ($this->app->compat_42) { $field->setAttr($attr); } else { throw $this->exception('4th argument to addField is obsolete'); } } return $field; }
/** * Adds button to the crud, which opens a new frame and returns page to * you. Add anything into the page as you see fit. The ID of the record * will be inside $crud->id. * * The format of $options is the following: * array ( * 'title'=> 'Click Me' // Header for the column * 'label'=> 'Click Me' // Text to put on the button * 'icon' => 'click-me' // Icon for button * ) * * @param string $name Unique name, also button and title default * @param array $options Options * * @return Page|bool Returns object if clicked on popup. */ public function addFrame($name, $options = array()) { if (!$this->model) { throw $this->exception('Must set CRUD model first'); } if (!is_array($options)) { throw $this->exception('Must be array'); } $s = $this->app->normalizeName($name); if ($this->isEditing('fr_' . $s)) { $n = $this->virtual_page->name . '_' . $s; if ($_GET[$n]) { $this->id = $_GET[$n]; $this->app->stickyGET($n); } return $this->virtual_page->getPage(); } if ($this->isEditing()) { return false; } $this->virtual_page->addColumn('fr_' . $s, $options['title'] ?: $name, array('descr' => $options['label'] ?: null, 'icon' => $options['icon'] ?: null), $this->grid); }