Module: Cms::Behaviors::Connecting::InstanceMethods
- Defined in:
- lib/cms/behaviors/connecting.rb
Instance Method Summary collapse
- #connect_to_page ⇒ Object
- #connected_page_count ⇒ Object
- #connected_pages ⇒ Object
- #content_block_type ⇒ Object
-
#content_name ⇒ Object
Returns a machine readable key that identifies the type of content this is.
- #display_name ⇒ Object
- #display_name_plural ⇒ Object
-
#supports_inline_editing? ⇒ Boolean
By default, all content types will support inline editing.
-
#update_connected_pages ⇒ Object
After blocks are updated, all pages they are connected to should also be updated, connecting the page to the new version of the block, as well as putting the pages into draft status if necessary.
Instance Method Details
#connect_to_page ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/cms/behaviors/connecting.rb', line 84 def connect_to_page unless connect_to_page_id.blank? || connect_to_container.blank? #Note that we are setting connected_page so that page can look at that #to determine if the page should be published self.connected_page = Page.find(connect_to_page_id) connected_page.create_connector(self, connect_to_container) end true end |
#connected_page_count ⇒ Object
68 69 70 |
# File 'lib/cms/behaviors/connecting.rb', line 68 def connected_page_count Page.currently_connected_to(self).count end |
#connected_pages ⇒ Object
63 64 65 66 |
# File 'lib/cms/behaviors/connecting.rb', line 63 def connected_pages return @connected_pages if @connected_pages @connected_pages = Page.connected_to(self) end |
#content_block_type ⇒ Object
72 73 74 |
# File 'lib/cms/behaviors/connecting.rb', line 72 def content_block_type self.class.content_block_type end |
#content_name ⇒ Object
Returns a machine readable key that identifies the type of content this is. Should match the key passed to ContentType.find_by_key
54 55 56 57 58 59 60 61 |
# File 'lib/cms/behaviors/connecting.rb', line 54 def content_name class_name = self.class.name if class_name.starts_with?("Cms::") class_name.demodulize.underscore else class_name.underscore end end |
#display_name ⇒ Object
76 77 78 |
# File 'lib/cms/behaviors/connecting.rb', line 76 def display_name self.class.display_name end |
#display_name_plural ⇒ Object
80 81 82 |
# File 'lib/cms/behaviors/connecting.rb', line 80 def display_name_plural self.class.display_name_plural end |
#supports_inline_editing? ⇒ Boolean
By default, all content types will support inline editing. Subclasses can override this.
95 96 97 |
# File 'lib/cms/behaviors/connecting.rb', line 95 def supports_inline_editing? true end |
#update_connected_pages ⇒ Object
After blocks are updated, all pages they are connected to should also be updated, connecting the page to the new version of the block, as well as putting the pages into draft status if necessary.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/cms/behaviors/connecting.rb', line 104 def update_connected_pages # If this is versioned, then we need make new versions of all the pages this is connected to if self.class.versioned? #logger.info "..... Updating connected pages for #{self.class} #{id} v#{version}" #Get all the pages the previous version of this connectable was connected to draft_version = draft.version connected_pages = Page.connected_to(:connectable => self, :version => (draft_version - 1)).to_a # puts "Found #{connected_pages}" connected_pages.each do |p| # This is needed in the case of updating page, # which updates this object, so as not to create a loop if p != updated_by_page #This just creates a new version of the page action = deleted? ? "Deleted" : "Edited" p.update_attributes(:version_comment => "#{self.class.name.demodulize} ##{id} was #{action}", :publish_on_save => false) #The previous step will copy over a connector pointing to the previous version of this connectable #We need to change that to point at the new version of this connectable connectors_for_page = p.connectors # puts "cfp #{connectors_for_page}" page_draft_version = p.draft.version cnn = connectors_for_page.for_page_version(page_draft_version) # puts "Connectors for page version #{page_draft_version} are #{cnn.all}" connectors = cnn.for_connectable(self) # puts "Found connectors #{connectors.all}" connectors.each do |con| con.update_attribute(:connectable_version, draft_version) end end end end true end |