src/source/dev_guide/howto-paragraph.rst
branchdoc-dc
changeset 122 7e69ecc9fd43
parent 117 1293a07cacb4
child 125 c8081c2ffe56
equal deleted inserted replaced
121:98a84761634f 122:7e69ecc9fd43
    98 
    98 
    99 
    99 
   100 Paragraph in the ZMI
   100 Paragraph in the ZMI
   101 """"""""""""""""""""
   101 """"""""""""""""""""
   102 
   102 
   103 
   103 1) Container Paragraph
   104 To display and manage the new paragraph in the ZMI, you should create this associated forms
   104 ----------------------
   105 
   105 
   106 1) Paragraph factory
   106 For example :py:class:`IParagraphContainerTarget`, it's a marker interface for paragraph containers.
   107 --------------------
       
   108 
   107 
   109 To create a new element instance inside the zodb, we need a container to this object. PyAMS provide
   108 To create a new element instance inside the zodb, we need a container to this object. PyAMS provide
   110 `IParagraphContainerTarget`, it's the default container for all paragraphs. We could use this container interface
   109 `IParagraphContainerTarget`, it's the default marker interface container for all paragraphs.
   111 as context to create a new paragraph.
   110 We could use this interface as context to declare a new pagelet.
   112 
   111 
   113 
   112 Definition of a Contact Phone form to create a new ContactPhone object
   114 Declaration of the **factory** of `ContactPhoneParagraph`
       
   115 
       
   116 .. code-block:: python
       
   117 
       
   118     @utility_config(name=CONTACT_PHONE_PARAGRAPH_TYPE, provides=IParagraphFactory)
       
   119     class ContactPhoneParagraphFactory(BaseParagraphFactory):
       
   120         """Contact paragraph factory"""
       
   121 
       
   122         name = _("Contact Phone card")
       
   123         content_type = ContactPhoneParagraph
       
   124         secondary_menu = True
       
   125 
       
   126 
       
   127 Definition of a form to create a new ContactPhone instance
       
   128 
   113 
   129 .. code-block:: python
   114 .. code-block:: python
   130 
   115 
   131     from pyams_form.form import ajax_config
   116     from pyams_form.form import ajax_config
   132 
   117 
   149             return ContactPhoneParagraph()
   134             return ContactPhoneParagraph()
   150 
   135 
   151         def add(self, object):
   136         def add(self, object):
   152             IParagraphContainer(self.context).append(object)
   137             IParagraphContainer(self.context).append(object)
   153 
   138 
       
   139 
       
   140 To display and manage the new paragraph in the ZMI, you should create this associated forms
   154 
   141 
   155 2) Create the Paragraph addform button in the menu
   142 2) Create the Paragraph addform button in the menu
   156 --------------------------------------------------
   143 --------------------------------------------------
   157 
   144 
   158 We have created a new form and we want add a quick access button to create a new paragraph
   145 We have created a new form and we want add a quick access button to create a new paragraph
   207                                                                                    ContactParagraphInnerEditForm))
   194                                                                                    ContactParagraphInnerEditForm))
   208             return output
   195             return output
   209 
   196 
   210 
   197 
   211 4) Create an Edit modal form
   198 4) Create an Edit modal form
   212 -----------------------------
   199 ----------------------------
   213 
   200 
   214 This form is used inside modals popup
   201 This form is used inside modals popup
   215 
   202 
   216 
   203 
   217 .. code-block:: python
   204 .. code-block:: python
   237 .. note::
   224 .. note::
   238 
   225 
   239     Select the new content block types in ZMI to make it available in tools
   226     Select the new content block types in ZMI to make it available in tools
   240 
   227 
   241     .. image:: ../_static/select_paragraph.png
   228     .. image:: ../_static/select_paragraph.png
       
   229 
       
   230 
       
   231 5) Paragraph Factory
       
   232 --------------------
       
   233 
       
   234 If you want to create automatically a paragraph object for a shared content you must define a factory
       
   235 
       
   236 Declaration of the **factory** of `ContactPhoneParagraph`
       
   237 
       
   238 .. code-block:: python
       
   239 
       
   240     @utility_config(name=CONTACT_PHONE_PARAGRAPH_TYPE, provides=IParagraphFactory)
       
   241     class ContactPhoneParagraphFactory(BaseParagraphFactory):
       
   242         """Contact paragraph factory"""
       
   243 
       
   244         name = _("Contact Phone card")
       
   245         content_type = ContactPhoneParagraph
       
   246         secondary_menu = True
       
   247 
       
   248 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.
   242 
   250 
   243 
   251 
   244 How to associate links or Illustrations to a Paragraph ?
   252 How to associate links or Illustrations to a Paragraph ?
   245 ========================================================
   253 ========================================================
   246 
   254