Back to Home

Drupal Bundle Inherit - module for inheriting entity types

drupal · drupal 7 · bundle inherit · drupal administration · node inherit · type inheritance

Drupal Bundle Inherit - module for inheriting entity types

    General idea


    The idea of ​​developing this module was (as often happens) dictated by its urgent need.

    Imagine that you are organizing an online store (or any other project in which you plan to create many different types of content). Suppose that you selected the Drupal 7 + Commerce bundle as a software package. Commerce provides the ability to create different types of products. This is useful when you are trading in different categories of goods, each of which has its own specific data. For example, for monitors, you most likely want to specify the type of matrix, and for processors, it would be nice to specify the clock frequency.

    Now imagine a situation where you need to organize a directory with many categories interconnected hierarchical relationships. For clarity, imagine a similar structure.

    Suppose for all products you want to indicate the country of manufacturer, manufacturer and year of manufacture. Call it the base type. Suppose you sell computers. All computers have common characteristics (operating system, number of usb ports, etc.). You sell laptops, desktops and tablets. All of them have the characteristics of computers and each has characteristics specific to them (for example, battery life for laptops).

    Thus, the following scheme is obtained.
    1. Base type
    2. Computers (inherit the base type)
    3. Laptops, PCs, tablets (inherit the type of "computers")

    What gives the module


    The Bundle Inherit module allows you to inherit it from one of the existing types of the same entity type when creating a new content type (entity bundles). In this case, all the fields available in the parent type are automatically attached to the newly created type.

    More interesting. The module supports two types of inheritance: soft and strict.

    In the case of the soft type of inheritance, the process will be as follows. When creating a new entity type, the fields of the selected parent type will simply be attached to it. On this, the module will finish its work and will not track these types in any way.

    In the case of strict inheritance, the following occurs. As in the case of soft inheritance, all fields of the parent type are attached to the new type. In this case, instances of inherited fields in the new type are blocked and become inaccessible for editing and deletion. Next, the module starts tracking the parent type. The module responds to 3 situations:
    1. When creating a new field, an instance of this field is automatically attached to all child types (types inherited from the parent).
    2. When a field instance is changed in the parent type, all changes are automatically transferred to the inherited instances.
    3. When a field instance is deleted from the parent type, in all child types the field is unlocked and becomes available for editing and deletion. In the future, it is planned to provide the user with the opportunity to agree or refuse to automatically delete fields and all associated data from child types.

    How is the module organized?


    A module is actually a set of two modules.

    The first (bundle_inherit module) provides an API for module developers and does not provide any functionality to the end user.

    The second (bundle_inherit_node module) is an example of using the Bundle Inherit API. Consisting of only 40 lines of code including comments, the module extends the node system module allowing you to inherit content types.

    Module usage


    From the point of view of the end user

    When creating a new content type, find the Inherit tab, check the corresponding item and select the parent type. This is it.

    From the point of view of the developer

    See the implementation using the example bundle_inherit_node module.
    All that is needed to add inheritance to an arbitrary type of entities is to find a form for creating a new type and use the bundle_inherit_attach_inherit_form function on it. Also, do not forget to add your submit callback to it and call the bundle_inherit_attach_inherit_form_submit function in it. And what’s called “that is the magic”.

    Prospects


    They are. It is planned to expand the functionality of the Bundle Inherit API to allow the application of inheritance logic not only to fields but also to integrate with the internal logic of different types of entities.
    Another possible direction for expanding the module is the ability to create abstract entity types. Types that can only be used for inheritance.

    Where to get


    Drupal.org: drupal.org/project/bundle_inherit
    GitHub: github.com/numesmat/Drupal-Bundle-Inherit

    Read Next