Key Features of Changing Content on CMS Bitrix

Imagine two colonies of marmots. Usually, these are peaceful animals that live in friendly families, but not in situations where the issue of occupied territory arises. This can happen between content editors and technical specialists. For an article to appear on the site, a well-established publishing process is needed. Editors should not touch the application code, and developers should provide convenient functionality for publications.

The article is intended for those who develop external company sites, site or business owners, as well as employees involved in external communications. The material will help writers and developers “find a balance” and help the latter avoid inconvenient technical problems in content management on 1C-Bitrix.

My name is Sergey Osokin, I work at NLMK-IT and am a leading developer for external sites of the NLMK group of companies, which includes such sites as nlmk.com, lipetsk.nlmk.com, india.nlmk.com, sgok.nlmk.com and others.

When using 1C-Bitrix BUS, content management can be a simple task for one user, or a complex task for dozens of content managers. In small projects, where the user is the sole owner of the site, he can easily manage all content, fill in news and edit texts from included areas without using Git. In such cases, everything happens quickly, and all project participants remain satisfied with the results of their work.

However, in the case of large projects, where content is managed by dozens of content managers, the situation can be more complex. Here, all the code is stored in Git, development processes are set up, and requests for prompt changes to information on the site are critical.

When it comes to changing information in the footer or in the include area, which is repeated in different sections of the site and stored in the repository, a problem arises. If you quickly change this information on the site, the master branch will no longer be relevant, and the next release is scheduled for next week. In such a situation, the question arises – what to do?

There was also a need for content managers to be able to manage the site structure, menu settings, SEO parameters (title, description, keyword) and create their own sections without changing the physical structure on the server. But this functionality in Bitrix is ​​strictly tied to the physical structure on the server. We can change it only by changing the repository.

The use of typical solutions seems completely absurd, the following problems arise:

1. We cannot refuse to use Git.

2. Included areas and index.php files may contain not only text, but also some PHP code, in which the content manager has no competence. Experience shows that they often do not have sufficient knowledge to work with it, which leads to system failures.

An analysis was carried out and requirements were formulated:

1. The content manager should have limited access to changing PHP files

2. The content manager should be able to change any content on the page

3. Content must change quickly

4. All code should be stored in Git

5. The solution must take into account multi-site

6. Content blocks should be reusable across pages

7. User-friendly interface

8. It is necessary to promptly change page headings, title, description, keywords. At the same time, the site code should not be affected

9. It is necessary to be able to create pages without resorting to the physical structure of the site

10. Dynamic menu creation

Based on the analysis, the following decisions were made:

1. Develop your own content management module, in which all content should be stored in the database in a separate highload-block.

2. Develop a virtual structure of the site based on an information block with the required properties.

Solution of the first problem

Data model for the content management module:

The ContentTable class is used to work with the data model.

Inside the class there are private properties $arContentTypes, $arHLBlock and $arHLFields.

The class contains the following static methods:

– getTableName(): returns the name of the table;

– getMap(): returns a map of table fields and their types.

The class also contains the following public methods:

– GetList($arParams = array()): returns a list of elements taking into account the specified parameters;

– Prepare2DB(&$arFields = array(), $method = 'ADD'): prepares data before saving to the database;

– AddEx($arFields = array()): adds a new element;

– Update($id, $arFields = array()): updates the data of the element with the specified ID;

– Delete($id): deletes the element with the specified id;

– getHLBlock(): returns an array with information about the highload block;

– getHLFields(): returns an array with information about the fields of the highload block;

– getContentTypes(): returns an array with information about content types;

– getContentTypeID2Code(): returns an array that maps content type IDs to their codes;

– getContentTypeCode2ID(): Returns an array that maps content type codes to their IDs.

The output of content will be regulated by the developed component. It can be placed anywhere on the page (Template, plug-in file or index.php). It is possible to calculate in advance where it may be necessary to place content.

Below is a description of the main methods of the CIContentComponent component:

1. onIncludeComponentLang(): This method is called before the language files of the component are included. It allows you to define the language messages that will be used in the component.

2. onPrepareComponentParams($params): The method is called before the component is executed and allows you to prepare the component parameters before using them. It allows you to check and convert parameters.

3. executeComponent(): The main method of the component, which performs all the necessary actions to obtain and process data. In this function, you can call other functions of the class and form the result of the component's work.

4. checkModules(): The method checks for the presence of the necessary modules for the component to work. If any module is missing, the method may display an error message or perform other actions.

5. checkParams(): The method checks for the presence of the required component parameters. If any parameter is missing or has an invalid value, the method may display an error message or perform other actions.

6. executeProlog(): The function performs some actions before the component is executed. For example, it can set the page title or add CSS and JS files.

7. readDataFromCache(): The method tries to get data from the cache. If the data is in the cache, the method returns it. If there is no data in the cache or it is out of date, the method returns false.

8. getResult(): The method generates the result of the component's work. It can be used to perform the necessary calculations and prepare data for output.

9. putDataToCache(): The method saves data to the cache. Data can be saved with a specific key and with additional parameters.

10. showEditButtons(): The method displays the edit buttons of the component if the user has the appropriate access rights.

11. executeEpilog(): The method performs some actions after the component is executed. For example, it can delete temporary files or free resources.

12. abortDataCache(): The method cancels saving data in the cache and clears the cache if it was created.

You can manage content from the public part

You can also change or add something in the administrative part.

Thus, content managers will no longer be able to change files such as index.php and include areas. This will ensure the security and stability of the system. At the same time, content managers are provided with a convenient interface for changing content in the editing mode of the public part of the site. Now content managers will be able to easily and quickly make the necessary changes to the content without resorting to changing php files. This will significantly simplify the work process and increase the efficiency of content managers.

Solution of the second problem

The idea was accepted to create a virtual structure based on the infoblock. Additional properties of this infoblock are listed below:

1. Show in menu – Type List

2. Menu Title – Type String

3. Link to external resource – Type String

4. Redirect to page – Element binding typeTo implement the task, a handler was created that went through the file structure on the server and created a clone of the physical structure in the infoblock structure. A folder on the server is an infoblock section, the index.php file is an infoblock element with the index.php symbol code. An additional agent updates the structure if something has changed on the server. Users who have the right to change the site structure infoblock can create sections that are not bound to the physical structure. When forming a site page, it is first checked whether there is such a section physically on the server and if so, it is displayed. If there is no such section on the server, but it is in the Site Structure infoblock, then a virtual page is displayed on which the content output component is displayed. The content manager can display information on the page using this component.

The menu was implemented in such a way that it is formed not from system files (for example, top.menu.php), but from the Site Structure info block. In the “Display in menu” property, you can choose in which menu to display this item. In the Name in menu property, you can edit the name if it differs from the title. The title and meta data for SEO are taken from the SEO tab. Additional settings for redirects and external links in the menu were also implemented.

For the convenience of filling virtual pages, snippets were implemented:

1. Accordion

2. Infographics

3. Slider

4. Tabs

5. Press release announcement

6. Manager's card

7. Quote

This approach allowed us to meet the customer's needs for prompt changes to information, while maintaining the stability of the main code and not disrupting development processes. In addition, it allowed content managers to work on changes in parallel, minimizing the risk of conflicts and accelerating the process of making changes.

As a result, we bypassed the inconvenient technical problems of content management on 1C-Bitrix, thereby making it possible to effectively manage the content and structure of the site in a large project with a large number of content managers.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *