├── language
└── english
│ └── entry_type_lang.php
├── addon.setup.php
├── views
├── option_row.php
└── options.php
├── css
└── EntryTypeFieldSettings.css
├── src
└── CreateFieldEntryTypeCommand.php
├── javascript
├── EntryTypeFieldSettings.js
└── EntryType.js
├── README.markdown
├── libraries
└── Entry_type.php
└── ft.entry_type.php
/language/english/entry_type_lang.php:
--------------------------------------------------------------------------------
1 | 'Field Type',
5 | 'types' => 'Types',
6 | 'confirm_delete_type' => 'Are you sure you want to delete this Type?',
7 | 'hide_fields' => 'Hide Fields',
8 | 'add_type' => 'Add Type',
9 | 'type_value' => 'Short Name',
10 | 'type_label' => 'Label',
11 | );
12 |
13 | /* End of file entry_type_lang.php */
14 | /* Location: ./system/expressionengine/third_party/entry_type/entry_type_lang.php */
--------------------------------------------------------------------------------
/addon.setup.php:
--------------------------------------------------------------------------------
1 | 'Entry Type',
5 | 'version' => '5.0.0',
6 | 'description' => 'A fieldtype for hiding publish fields on a conditional basis.',
7 | 'namespace' => '\\',
8 | 'author' => 'Rob Sanchez',
9 | 'author_url' => 'https://github.com/rsanchez',
10 | 'docs_url' => 'https://github.com/rsanchez/entry_type',
11 | 'settings_exist' => false,
12 | 'fieldtypes' => array(
13 | 'entry_type' => array(
14 | 'name' => 'Entry Type',
15 | ),
16 | )
17 | );
18 |
--------------------------------------------------------------------------------
/views/option_row.php:
--------------------------------------------------------------------------------
1 |
2 | | =form_input(sprintf('entry_type_options[0][%s][value]', $i), $value)?> |
3 | =form_input(sprintf('entry_type_options[0][%s][label]', $i), $label)?> |
4 |
5 | $field_name) : ?>
6 |
10 |
11 | |
12 | |
13 |
14 |
--------------------------------------------------------------------------------
/css/EntryTypeFieldSettings.css:
--------------------------------------------------------------------------------
1 | .entry_type_remove_row:before {
2 | content: '\f1f8';
3 | color: #1f80bd;
4 | font-family: FontAwesome;
5 | display: inline-block;
6 | -webkit-font-smoothing: antialiased;
7 | font-size: 1.5em;
8 | }
9 |
10 | .entry_type_options tbody tr:last-child td {
11 | border-bottom: 1px solid #e6e6e6;
12 | }
13 |
14 | .entry_type_hide_fields {
15 | display: block;
16 | }
17 |
18 | .entry_type_add_row .icon.plus:before {
19 | content: '\f067';
20 | }
21 |
22 | /* EE6+ specific styles. Use FA icons instead. */
23 | body[data-ee-version] .entry_type_add_row .icon.plus:before,
24 | body[data-ee-version] .entry_type_remove_row:before {
25 | content: "";
26 | }
27 |
28 | body[data-ee-version] .entry_type_remove_row {
29 | color: var(--ee-danger);
30 | }
31 |
--------------------------------------------------------------------------------
/views/options.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | | =lang('type_value')?> |
5 | =lang('type_label')?> |
6 | =lang('hide_fields')?> |
7 | |
8 |
9 |
10 |
11 |
12 | $data) : ?>
13 | =$this->load->view('option_row', array('i' => (string) $i, 'value' => $value, 'label' => $data['label'], 'hide_fields' => $data['hide_fields'], 'fields' => $fields), TRUE)?>
14 |
15 |
16 |
17 |
18 |
19 | |
20 | =lang('add_type')?>
21 | |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/CreateFieldEntryTypeCommand.php:
--------------------------------------------------------------------------------
1 | $this->option('fieldtype'),
44 | );
45 | }
46 | }
--------------------------------------------------------------------------------
/javascript/EntryTypeFieldSettings.js:
--------------------------------------------------------------------------------
1 | var EntryTypeFieldSettings;
2 | (function() {
3 | EntryTypeFieldSettings = function(container, options) {
4 |
5 | options = $.extend({
6 | fieldName: "entry_type_options",
7 | sortable: true,
8 | rowTemplate: "",
9 | deleteConfirmMsg: "Are you sure you want to delete this Type?"
10 | }, options);
11 |
12 | var self = this;
13 |
14 | this.$container = $(container);
15 | this.$container.data("EntryTypeFieldSettings", this);
16 | this.$tbody = this.$container.find("tbody:first");
17 | this.addRow = function() {
18 | self.$tbody.append(options.rowTemplate.replace(/\{\{INDEX\}\}/g, self.$tbody.find("tr").length));
19 | };
20 | this.removeRow = function(index) {
21 | self.$tbody.find("tr").eq(index).remove();
22 | self.orderRows();
23 | };
24 | this.orderRows = function() {
25 | self.$tbody.find("tr").each(function(index){
26 | $(this).find(":input").each(function(){
27 | var match = $(this).attr("name").match(new RegExp("^"+options.fieldName+"\\[([a-z:\\d]+)\\]\\[\\d+\\]\\[(.*?)\\]$"));
28 | if (match) {
29 | $(this).attr("name", options.fieldName+"["+match[1]+"]["+index+"]["+match[2]+"]");
30 | }
31 | });
32 | });
33 | };
34 |
35 | this.$container.on("click", ".entry_type_add_row", self.addRow);
36 | this.$container.on("click", ".entry_type_remove_row", function(){
37 | if (confirm(options.deleteConfirmMsg)) {
38 | self.removeRow($(this).parents("tbody").find(".entry_type_remove_row").index(this));
39 | }
40 | });
41 | if (options.sortable) {
42 | this.$tbody.sortable({
43 | stop: function(e, ui) {
44 | self.orderRows();
45 | }
46 | }).children("tr").css({cursor:"move"});
47 | }
48 |
49 | };
50 | })();
--------------------------------------------------------------------------------
/README.markdown:
--------------------------------------------------------------------------------
1 | # Entry Type
2 |
3 | An ExpressionEngine 4 add-on for hiding publish fields on a conditional basis. The Entry Type fieldtype creates a dropdown field which can hide other publish fields depending on the value chosen.
4 |
5 | Use the [`ee2`](/rsanchez/entry_type/tree/ee2) branch for an EE2 compatible version. Structure/Pages module compatibility has been removed in the EE3 version.
6 |
7 | Use the [`ee3`](/rsanchez/entry_type/tree/ee3) branch for an EE3 compatible version.
8 |
9 | ## Installation
10 |
11 | * Requires PHP 5.3
12 | * Download the addon and rename the folder to `entry_type`
13 | * Copy to `system/user/addons`
14 | * Install the addon
15 |
16 | ## Fieldtype Tags
17 |
18 | {your_field_name}
19 |
20 | The short name for the entry type selected.
21 |
22 | {your_field_name:label}
23 |
24 | The label for the entry type selected.
25 |
26 | {if {your_field_name:selected option="link"}}
27 |
28 | Check whether the specified option is selected. (Use the short name).
29 |
30 | {your_field_name all_options="yes"}
31 | {option} {option_name} {label} {selected}
32 | {/your_field_name}
33 |
34 | List all your options.
35 |
36 | ## Fieldtype Settings
37 |
38 | - Short Name - the value of the field, for use in templates and conditionals
39 | - Label - the label for the value
40 | - Hide Fields - choose the fields to hide when the specified value is chosen
41 |
42 | ## Examples
43 |
44 | Displaying different content based on entry type.
45 |
46 | {exp:channel:entries}
47 | {title}
48 | {your_entry_type_field:label}
49 | {if your_entry_type_field == 'link'}
50 | {link_url}
51 | {if:else your_entry_type_field == 'video'}
52 | {video}
53 | {if:elseif your_entry_type_field == 'image'}
54 | {image}
55 | {/if}
56 | {/exp:channel:entries}
57 |
--------------------------------------------------------------------------------
/javascript/EntryType.js:
--------------------------------------------------------------------------------
1 | (function(w) {
2 |
3 | $("form.ajax-validate fieldset").each(function() {
4 | var $fieldset = $(this);
5 | var $input = $fieldset.find('[name^=field_id_]:first').each(function() {
6 | var match = this.name.match(/^field_id_(\d+)/);
7 | $fieldset.attr("id", 'hold_field_' + match[1]);
8 | });
9 | });
10 |
11 | var $holdFields = $("fieldset[id^=hold_field_]").filter(function() {
12 | var match = this.id.match(/^hold_field_(\d+)$/);
13 |
14 | if (match) {
15 | $(this).addClass('entry-type-field-' + match[1]);
16 |
17 | return true;
18 | }
19 |
20 | return false;
21 | });
22 |
23 | var $tabs = $(".tab-wrap .tabs").find("li");
24 |
25 | // add grid fields
26 | var $gridHoldFields = $('.fieldset-faux').filter(function() {
27 | var $gridField = $(this).find('.grid-field');
28 |
29 | if ($gridField.length) {
30 | var match = $gridField.attr('id').match(/^field_id_(\d+)$/);
31 |
32 | if (match) {
33 | $(this).addClass('entry-type-field-' + match[1]);
34 |
35 | return true;
36 | }
37 | }
38 |
39 | return false;
40 | });
41 |
42 | // Selector is very specific b/c the