src/source/dev_guide/howto-paragraph.rst
branchdoc-dc
changeset 125 c8081c2ffe56
parent 122 7e69ecc9fd43
child 126 e0584f3de3fd
equal deleted inserted replaced
124:696f58cb5bdd 125:c8081c2ffe56
     1 .. _paragraphhowto:
     1 .. _paragraphhowto:
     2 
     2 
     3 
     3 Creating new Paragraph (or blocks)
     4 How to create a Paragraph type?
     4 ==================================
     5 ===============================
       
     6 
     5 
     7 Paragraphs or Blocks are components that contain elements/fields and provide one or many renderer methods to compose
     6 Paragraphs or Blocks are components that contain elements/fields and provide one or many renderer methods to compose
     8 the front office website
     7 the front office website
     9 
     8 
    10 
     9 How to create a Paragraph type?
    11 Create a Paragraph
    10 -------------------------------
    12 """"""""""""""""""
    11 
    13 
    12 
    14 In this example we will create a contact paragraph to display at the user, who to contact.
    13 In this example we will create a contact paragraph to display at the user, who to contact.
    15 
    14 
    16 1) Interface
    15 1) Interface
    17 ------------
    16 ^^^^^^^^^^^^
    18 
    17 
    19 At first we create a new paragraph interface.
    18 At first we create a new paragraph interface.
    20 
    19 
    21 .. code-block:: python
    20 .. code-block:: python
    22 
    21 
    45 
    44 
    46 
    45 
    47 
    46 
    48 
    47 
    49 2) Implement the interface
    48 2) Implement the interface
    50 --------------------------
    49 ^^^^^^^^^^^^^^^^^^^^^^^^^^
    51 
    50 
    52 An implementation of the interface
    51 An implementation of the interface
    53 
    52 
    54 .. code-block:: python
    53 .. code-block:: python
    55 
    54 
    77             if IImage.providedBy(self._photo):
    76             if IImage.providedBy(self._photo):
    78                 alsoProvides(self._photo, IResponsiveImage)
    77                 alsoProvides(self._photo, IResponsiveImage)
    79 
    78 
    80 
    79 
    81 3) Renderers Vocabulary
    80 3) Renderers Vocabulary
    82 -----------------------
    81 ^^^^^^^^^^^^^^^^^^^^^^^
    83 
    82 
    84 The list of rendered available for a paragraph is build automatically and is based on adapters that provide this interface
    83 The list of rendered available for a paragraph is build automatically and is based on adapters that provide this interface
    85 
    84 
    86 .. code-block:: python
    85 .. code-block:: python
    87 
    86 
    96 
    95 
    97     :ref:`rendererhowto`
    96     :ref:`rendererhowto`
    98 
    97 
    99 
    98 
   100 Paragraph in the ZMI
    99 Paragraph in the ZMI
   101 """"""""""""""""""""
   100 --------------------
   102 
   101 
   103 1) Container Paragraph
   102 1) Container Paragraph
   104 ----------------------
   103 ^^^^^^^^^^^^^^^^^^^^^^
   105 
   104 
   106 For example :py:class:`IParagraphContainerTarget`, it's a marker interface for paragraph containers.
   105 For example :py:class:`IParagraphContainerTarget`, it's a marker interface for paragraph containers.
   107 
   106 
   108 To create a new element instance inside the zodb, we need a container to this object. PyAMS provide
   107 To create a new element instance inside the zodb, we need a container to this object. PyAMS provide
   109 `IParagraphContainerTarget`, it's the default marker interface container for all paragraphs.
   108 `IParagraphContainerTarget`, it's the default marker interface container for all paragraphs.
   138 
   137 
   139 
   138 
   140 To display and manage the new paragraph in the ZMI, you should create this associated forms
   139 To display and manage the new paragraph in the ZMI, you should create this associated forms
   141 
   140 
   142 2) Create the Paragraph addform button in the menu
   141 2) Create the Paragraph addform button in the menu
   143 --------------------------------------------------
   142 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   144 
   143 
   145 We have created a new form and we want add a quick access button to create a new paragraph
   144 We have created a new form and we want add a quick access button to create a new paragraph
   146 
   145 
   147 .. code-block:: python
   146 .. code-block:: python
   148 
   147 
   157         paragraph_type = CONTACT_PARAGRAPH_TYPE
   156         paragraph_type = CONTACT_PARAGRAPH_TYPE
   158 
   157 
   159 
   158 
   160 
   159 
   161 3) Create Edit inner form
   160 3) Create Edit inner form
   162 -------------------------
   161 ^^^^^^^^^^^^^^^^^^^^^^^^^
   163 
   162 
   164 .. code-block:: python
   163 .. code-block:: python
   165 
   164 
   166     @adapter_config(context=(IContactPhoneParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
   165     @adapter_config(context=(IContactPhoneParagraph, IPyAMSLayer), provides=IParagraphInnerEditor)
   167                 permission=MANAGE_CONTENT_PERMISSION)
   166                 permission=MANAGE_CONTENT_PERMISSION)
   194                                                                                    ContactParagraphInnerEditForm))
   193                                                                                    ContactParagraphInnerEditForm))
   195             return output
   194             return output
   196 
   195 
   197 
   196 
   198 4) Create an Edit modal form
   197 4) Create an Edit modal form
   199 ----------------------------
   198 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   200 
   199 
   201 This form is used inside modals popup
   200 This form is used inside modals popup
   202 
   201 
   203 
   202 
   204 .. code-block:: python
   203 .. code-block:: python
   227 
   226 
   228     .. image:: ../_static/select_paragraph.png
   227     .. image:: ../_static/select_paragraph.png
   229 
   228 
   230 
   229 
   231 5) Paragraph Factory
   230 5) Paragraph Factory
   232 --------------------
   231 ^^^^^^^^^^^^^^^^^^^^
   233 
   232 
   234 If you want to create automatically a paragraph object for a shared content you must define a factory
   233 If you want to create automatically a paragraph object for a shared content you must define a factory
   235 
   234 
   236 Declaration of the **factory** of `ContactPhoneParagraph`
   235 Declaration of the **factory** of `ContactPhoneParagraph`
   237 
   236 
   248 When the contributors will create new shared content with predefined paragraphs,
   247 When the contributors will create new shared content with predefined paragraphs,
   249 it's the container factory class that will be used to create the paragraph object.
   248 it's the container factory class that will be used to create the paragraph object.
   250 
   249 
   251 
   250 
   252 How to associate links or Illustrations to a Paragraph ?
   251 How to associate links or Illustrations to a Paragraph ?
   253 ========================================================
   252 --------------------------------------------------------
   254 
   253 
   255 Adding the following marker interface, we add new behavior to the Paragraph `ContactPhoneParagraph` .
   254 Adding the following marker interface, we add new behavior to the Paragraph `ContactPhoneParagraph` .
   256 
       
   257 
       
   258 Paragraph advanced
       
   259 """"""""""""""""""
       
   260 
       
   261 You can attach Associated files, links or illustration and manage them directly through the rubric `Links and Attachments`.
   255 You can attach Associated files, links or illustration and manage them directly through the rubric `Links and Attachments`.
   262 
   256 
   263 .. image:: ../_static/select_links_n_attachment.png
   257 .. image:: ../_static/select_links_n_attachment.png
   264 
   258 
   265 
   259 
   266 1) Paragraph with Links and Attachements
   260 1) Paragraph with Links and Attachements
   267 ----------------------------------------
   261 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   268 
   262 
   269 To "activate" this features the paragrath object must to implement specific interface
   263 To "activate" this features the paragrath object must to implement specific interface
   270 
   264 
   271 
   265 
   272 .. code-block:: python
   266 .. code-block:: python
   316 .. image:: ../_static/select_add_links.png
   310 .. image:: ../_static/select_add_links.png
   317 
   311 
   318 
   312 
   319 
   313 
   320 2) Add link and association form
   314 2) Add link and association form
   321 --------------------------------
   315 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   322 
   316 
   323 You can add form to manage links and attachments directly in paragraph form to do that your form must implement
   317 You can add form to manage links and attachments directly in paragraph form to do that your form must implement
   324 ``IPropertiesEditForm`` and/or  ``IAssociationParentForm``
   318 ``IPropertiesEditForm`` and/or  ``IAssociationParentForm``
   325 
   319 
   326 
   320