FOF30\Form\Field\Text::getRepeatable PHP Метод

getRepeatable() публичный Метод

Get the rendering of this field type for a repeatable (grid) display, e.g. in a view listing many item (typically a "browse" task)
С версии: 2.0
public getRepeatable ( ) : string
Результат string The field HTML
    public function getRepeatable()
    {
        if (is_array($this->value)) {
            $this->value = print_r($this->value, true);
        }
        if (isset($this->element['legacy'])) {
            return $this->getInput();
        }
        // Should I support checked-out elements?
        $checkoutSupport = false;
        if (isset($this->element['checkout'])) {
            $checkoutSupportValue = (string) $this->element['checkout'];
            $checkoutSupport = in_array(strtolower($checkoutSupportValue), array('yes', 'true', 'on', 1));
        }
        // Initialise
        $class = $this->class ? $this->class : $this->id;
        $format_string = $this->element['format'] ? (string) $this->element['format'] : '';
        $format_if_not_empty = in_array((string) $this->element['format_if_not_empty'], array('true', '1', 'on', 'yes'));
        $parse_value = in_array((string) $this->element['parse_value'], array('true', '1', 'on', 'yes'));
        $link_url = $this->element['url'] ? (string) $this->element['url'] : '';
        $empty_replacement = $this->element['empty_replacement'] ? (string) $this->element['empty_replacement'] : '';
        $format_source_file = empty($this->element['format_source_file']) ? '' : (string) $this->element['format_source_file'];
        $format_source_class = empty($this->element['format_source_class']) ? '' : (string) $this->element['format_source_class'];
        $format_source_method = empty($this->element['format_source_method']) ? '' : (string) $this->element['format_source_method'];
        if ($link_url && $this->item instanceof DataModel) {
            $link_url = $this->parseFieldTags($link_url);
        } else {
            $link_url = false;
        }
        // Get the (optionally formatted) value
        $value = $this->value;
        if (!empty($empty_replacement) && empty($this->value)) {
            $value = JText::_($empty_replacement);
        }
        if ($parse_value) {
            $value = $this->parseFieldTags($value);
        }
        if (!empty($format_string) && (!$format_if_not_empty || $format_if_not_empty && !empty($this->value))) {
            $format_string = $this->parseFieldTags($format_string);
            $value = sprintf($format_string, $value);
        } elseif ($format_source_class && $format_source_method) {
            // Maybe we have to load a file?
            if (!empty($format_source_file)) {
                $format_source_file = $this->form->getContainer()->template->parsePath($format_source_file, true);
                if ($this->form->getContainer()->filesystem->fileExists($format_source_file)) {
                    include_once $format_source_file;
                }
            }
            // Make sure the class and method exist
            if (class_exists($format_source_class, true) && in_array($format_source_method, get_class_methods($format_source_class))) {
                $value = $format_source_class::$format_source_method($value);
                $value = $this->parseFieldTags($value);
            } else {
                $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
            }
        } else {
            $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
        }
        // Create the HTML
        $html = '<span class="' . $class . '">';
        $userId = $this->form->getContainer()->platform->getUser()->id;
        if ($checkoutSupport && $this->item->isLocked($userId)) {
            $key_field = $this->item->getKeyName();
            $key_id = $this->item->{$key_field};
            $lockedBy = '';
            $lockedOn = '';
            if ($this->item->hasField('locked_by')) {
                $lockedUser = $this->form->getContainer()->platform->getUser($this->item->getFieldValue('locked_by'));
                $lockedBy = $lockedUser->name . ' (' . $lockedUser->username . ')';
            }
            if ($this->item->hasField('locked_on')) {
                $lockedOn = $this->item->getFieldValue('locked_on');
            }
            $html .= \JHtml::_('jgrid.checkedout', $key_id, $lockedBy, $lockedOn, '', true);
        }
        if ($link_url) {
            $html .= '<a href="' . $link_url . '">';
        }
        $html .= $value;
        if ($link_url) {
            $html .= '</a>';
        }
        $html .= '</span>';
        return $html;
    }

Usage Example

Пример #1
0
 /**
  * Get the rendering of this field type for a repeatable (grid) display,
  * e.g. in a view listing many item (typically a "browse" task)
  *
  * @since 2.0
  *
  * @return  string  The field HTML
  */
 public function getRepeatable()
 {
     // Initialise
     $slug_field = isset($this->element['slug_field']) ? (string) $this->element['slug_field'] : $this->item->getFieldAlias('slug');
     $slug_format = $this->element['slug_format'] ? (string) $this->element['slug_format'] : '(%s)';
     $slug_class = $this->element['slug_class'] ? (string) $this->element['slug_class'] : 'small';
     // Get the regular display
     $html = parent::getRepeatable();
     $slug = $this->item->{$slug_field};
     $html .= '<br />' . '<span class="' . $slug_class . '">';
     $html .= JText::sprintf($slug_format, $slug);
     $html .= '</span>';
     return $html;
 }
All Usage Examples Of FOF30\Form\Field\Text::getRepeatable