Sha256: 83f85ba83c46a696e88e6f15a67691d1bccb95d1a22a414e0d361c579264803d

Contents?: true

Size: 1.72 KB

Versions: 26

Compression:

Stored size: 1.72 KB

Contents

module Plugins
  module Core
    class ContentItemCell < Plugins::Core::Cell
      def popup
        render
      end

      private

      def value
        data&.[]('content_item_id')
      end

      def associated_content_item
        ContentItem.find_by_id(value)
      end

      def associated_primary_field
        associated_content_item.content_type.fields.find_by_name(field.metadata['field_name'])
      end

      def associated_primary_field_type_class
        associated_primary_field.field_type_instance.class
      end

      def associated_primary_field_item
        associated_content_item.field_items.find_by_field_id associated_primary_field
      end

      def associated_content_item_title
        # Gross hack, this should rely on 'primary title field' config feature in future, and should use a scope
        title_field_item = associated_content_item.field_items.find do |field_item|
          field_item.field.name == 'Title'
        end

        title_field_item.data['text']
      end

      def render_label
        "Select #{field.name}"
      end

      def render_content_item_id
        @options[:form].hidden_field 'data[content_item_id]', value: value, class: 'association_content_item_id'
      end

      def render_association_cell
        cell(Plugins::Core::AssetCell, associated_primary_field_item,
             associated_content_item: associated_content_item,
             associated_primary_field: associated_primary_field,
             associated_primary_field_type_class: associated_primary_field_type_class,
             associated_primary_field_item: associated_primary_field_item,
             associated_content_item_title: associated_content_item_title)
        .(:association)
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
cortex-plugins-core-2.1.1 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-2.1.0 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-2.0.1 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-1.1.1 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-1.1.0 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-1.0.0 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.12.4 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.12.3 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.12.2 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.12.1 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.12.0 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.11.3 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.11.2 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.11.1 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.11.0 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.10.4 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.10.2 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.10.1 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.10.0 app/cells/plugins/core/content_item_cell.rb
cortex-plugins-core-0.9.1 app/cells/plugins/core/content_item_cell.rb