Module: Pageflow::EntriesControllerEnvHelper

Defined in:
lib/pageflow/entries_controller_env_helper.rb

Overview

A helper module that can be included in an entry type’s frontend app to access the PublishedEntry.

Since:

  • 15.1

Class Method Summary collapse

Class Method Details

.add_entry_info_to_env(env, entry:, mode: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 15.1



32
33
34
# File 'lib/pageflow/entries_controller_env_helper.rb', line 32

def self.(env, entry:, mode: nil)
  env['pageflow'] = {'published_entry' => entry, 'entry_mode' => mode}
end

.get_entry_mode_from_env(env = request.env) ⇒ Object

Returns ‘:preview` if a signed in user is currently viewing the entry via the preview feature. Returns `:published` if the entry is rendered on a publicly available site. The information will be placed in the request env by the Pageflow engine before delegating to the entry type’s frontend app.

Use EntriesControllerTestHelper to set up the request environment in controller tests.

Since:

  • 15.1



27
28
29
# File 'lib/pageflow/entries_controller_env_helper.rb', line 27

def get_entry_mode_from_env(env = request.env)
  EntriesControllerEnvHelper.get_pageflow_hash(env)['entry_mode']
end

.get_pageflow_hash(env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 15.1



37
38
39
40
41
42
# File 'lib/pageflow/entries_controller_env_helper.rb', line 37

def self.get_pageflow_hash(env)
  env.fetch('pageflow') do
    throw('Missing pageflow key in request env. Use Pageflow::EntriesControllerTestHelper ' \
          'to set it in controller tests.')
  end
end

.get_published_entry_from_env(env = request.env) ⇒ Object

Read the PublishedEntry from the request env. It will be placed there by the Pageflow engine before delegating to the entry type’s frontend app.

Use EntriesControllerTestHelper to set up the request environment in controller tests.

Since:

  • 15.1



15
16
17
# File 'lib/pageflow/entries_controller_env_helper.rb', line 15

def get_published_entry_from_env(env = request.env)
  EntriesControllerEnvHelper.get_pageflow_hash(env)['published_entry']
end