Coder Social home page Coder Social logo

jpathru / attributes Goto Github PK

View Code? Open in Web Editor NEW
15.0 6.0 2.0 117 KB

Компонент реализует дополнительные атрибуты для элементов системы, меню, материалов, категорий, модулей и плагинов.

License: GNU General Public License v3.0

PHP 100.00%
joomla joomla-extensions joomla-component joomla-cms joomla-package

attributes's Introduction

Attributes

Last Update Version Joomla Php

description in Russian here

The component implements additional attributes for:

  • system params,
  • menu,
  • users,
  • contacts,
  • articles,
  • categories,
  • modules,
  • plugins,
  • fields,
  • tags.

The following attribute types are implemented:

  • text (type="text"),
  • multiline text (type="textarea"),
  • editor (type="editor"),
  • list (type="list"),
  • image (type="media").

Type list supports the multiple value option.

Type multiline text supports the standard Joomla content filtering types: html, raw and others.

WARNING! Types multiline text and editor are not recommended for system parameters: when restoring a site using Akeeba Backup, parameter values may be lost.

Attribute values are stored in the parameters of the corresponding element, the params field (for articles in the attribs field).

Every attribute name is prefixed with attrs_ prefix. You can get the attribute value by the standard way described below.

For each attribute, it is possible to specify an individual output layout. Layouts are created in the /templates/{your_template}/html/layouts/com_attrs/ folder and are assigned to each attribute separately. The attribute data inside the layout is contained in the $displayData structure. The default layout does not contain markup.

Usage

Shortcode, for use in content editor

{attrs;dest;id;attrName[;layout]}
  • attrs - reserved word
  • dest - belonging to a specific type of record, one of: system, menu, users, contacts, articles, categories, modules, plugins
  • id - ID of the corresponding entry for the specified property, specify 0 for systems
  • attrName - attribute system name
  • layout - output layout (optional), if 0 or false is specified, the assigned layout will be ignored and the attribute value will be displayed without layout; format for specifying the layout: template:layoutname, where template is the main template of the site that contains the override (specify the underscore to indicate the default template), layoutname is the name of the overridden layout file, without extension; when specifying a nonexistent layout, the attribute value will not be displayed

Important: Unpublished attributes are ignored. Images are output without markup, only the path. Arrays are displayed as a list of values separated by commas.

Example: You have created an attribute with the name test for a material with ID = 5, to get its value, insert the following line in the editor: {attrs;articles;5;test}. If you want to display the attribute indicating the override of the template created with the name mytemplate in the main protostar site template, insert the following line into the editor: {attrs;articles;5;test;protostar:mytemplate}.

With helper

It is recommended because it checks the status of the attribute (published / unpublished) and it is not necessary to specify the prefix attrs_. Do not specify the third parameter or set it to zero to get the attribute value from the system configuration.

/*
AttrsHelper::ATTR_DEST_SYSTEM = 'system'
AttrsHelper::ATTR_DEST_MENU = 'menu'
AttrsHelper::ATTR_DEST_USERS = 'users'
AttrsHelper::ATTR_DEST_CONTACTS = 'contacts'
AttrsHelper::ATTR_DEST_ARTICLES = 'articles'
AttrsHelper::ATTR_DEST_CATEGORIES = 'categories'
AttrsHelper::ATTR_DEST_MODULES = 'modules'
AttrsHelper::ATTR_DEST_PLUGINS = 'plugins'
AttrsHelper::ATTR_DEST_FIELDS = 'fields'
AttrsHelper::ATTR_DEST_TAGS = 'tags'
*/

JLoader::register('AttrsHelper', JPATH_ADMINISTRATOR . '/components/com_attrs/helpers/attrs.php');

// output with the layout specified in the attribute parameters
$attrValue = AttrsHelper::getAttr($attrName, AttrsHelper::ATTR_DEST_ARTICLES, $article->id);

// priority layout output
// the attribute layout will be loaded /templates/protostar/html/layouts/com_attrs/mytemplate.php
$attrValue = AttrsHelper::getAttr($attrName, AttrsHelper::ATTR_DEST_ARTICLES, $article->id, 'protostar:mytemplate');

Without helper (not recommended)

This method does not support attribute standardization.

// default
$attrValue = $item->params->get("arrts_$attrName", '');

// for system
$attrValue = Joomla\CMS\Factory::getConfig->get("arrts_$attrName", '');

// for articles
$attribs = json_decode($article->attribs, true);
$attrValue = $attribs["arrts_$attrName"];

attributes's People

Contributors

alekvolsk avatar b2z avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

attributes's Issues

Дополнить readme

Нужно ещё больше пояснений, как использовать.
Видео обзор/ изображения было бы здорово. С примерами.

Always use the API for the assets

This

<script type="text/javascript">

will work only if the core.js gets loaded before this part of the page gets parsed (eg core.js in the head). If in my template the core.js script is called on the end of the body your code will not work as it will be overrides by core.js. Order of execution matters in JS, thus ALWAYS use the Joomla API for css and javascript (inline or files)...

Добавить шаблоны вывода

Добавить ещё один параметр - шаблон вывода значения поля. Сами шаблоны можно оформить, как это сделано в modules.php. По файлу, на каждый тип поля, а в нём - каждая функция - описание нового представления. Либо, просто дёргать файл, с названием шаблона. Но, главное, чтобы была возможность наплодить шаблонов, сколько душе захочется.
По применению:
Например, я вывожу ссылки на соц сети плагином. Чтобы не писать один и тот же код несколько раз, было бы удобно создать шаблон вывода и просто вызывать атрибут, указав нужный шаблон.
Примеров применения много. Например, ещё я вывожу плагином телефоны и адреса электронной почты.

Системное имя

Добавить автогенерацию системного имени.
Можно использовать как joomla формирует alias

Странный баг с АкибаБэкапом

При переносе сайта акибой, почему то очищаются значения, в поле, типа textarea
Обычные текстовые поля - на месте, а вот многострочные - пустые

Просьба поменять разделитель | в шорткоде на любой другой символ

Так как в описании символ | традиционно обозначает "или", то применение этого символа в шорткоде создает путаницу. В описании он воспринимается как выбор или того или другого.
Просьба поменять этот разделитель на любой другой символ.
например - #

Шорткоды

Расширить функционал возможностью получения значения любого атрибута через шорткоды (контент-плаг, кнопка под редактор)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.