Skip to content

Commit

Permalink
Allow limits to be set to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
nilshoerrmann committed Jun 12, 2014
1 parent b2c9ed7 commit c3da800
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
4 changes: 4 additions & 0 deletions extension.meta.xml
Expand Up @@ -13,7 +13,11 @@
</author>
</authors>
<releases>
<release version="0.2.0" date="2014-06-05" min="2.4">
- Added entry limit to markup
</release>
<release version="0.1.0" date="2014-06-05" min="2.4">
- Added association interfaces
- Initial release (forked Select Box Link)
</release>
</releases>
Expand Down
38 changes: 21 additions & 17 deletions fields/field.association.php
Expand Up @@ -102,6 +102,7 @@ public function findOptions(array $existing_selection=NULL,$entry_id=NULL)

if (is_array($sections) && !empty($sections)) {
foreach ($sections as $_section) {
$results = array();

$section = SectionManager::fetch($_section['id']);
$group = array(
Expand All @@ -110,12 +111,12 @@ public function findOptions(array $existing_selection=NULL,$entry_id=NULL)
'values' => array()
);

EntryManager::setFetchSorting($section->getSortingField(), $section->getSortingOrder());
$entries = EntryManager::fetch(NULL, $section->get('id'), $limit, 0, null, null, false, false);

$results = array();
foreach ($entries as $entry) {
$results[] = (int) $entry['id'];
if ($limit > 0) {
EntryManager::setFetchSorting($section->getSortingField(), $section->getSortingOrder());
$entries = EntryManager::fetch(NULL, $section->get('id'), $limit, 0, null, null, false, false);
foreach ($entries as $entry) {
$results[] = (int) $entry['id'];
}
}

// If a value is already selected, ensure it is added to the list (if it isn't in the available options)
Expand Down Expand Up @@ -328,10 +329,10 @@ protected function findRelatedValues(array $relation_id = array())
}

$relation_data[] = array(
'id' => $entry->get('id'),
'section_handle' => $section_info[$section_id]['handle'],
'section_name' => $section_info[$section_id]['name'],
'value' => $value
'id' => $entry->get('id'),
'section_handle' => $section_info[$section_id]['handle'],
'section_name' => $section_info[$section_id]['name'],
'value' => $value
);
}
}
Expand Down Expand Up @@ -562,6 +563,9 @@ public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWit
if (!is_null($flagWithError)) {
$wrapper->appendChild(Widget::Error($label, $flagWithError));
} else $wrapper->appendChild($label);

// Set entry limit
$wrapper->setAttribute('data-limit', $this->get('limit'));
}

public function processRawFieldData($data, &$status, &$message=null, $simulate=false, $entry_id=null)
Expand Down Expand Up @@ -660,8 +664,8 @@ public function prepareTableValue($data, XMLElement $link = null, $entry_id = nu
public function getImportModes()
{
return array(
'getValue' => ImportableField::STRING_VALUE,
'getPostdata' => ImportableField::ARRAY_VALUE
'getValue' => ImportableField::STRING_VALUE,
'getPostdata' => ImportableField::ARRAY_VALUE
);
}

Expand Down Expand Up @@ -707,16 +711,16 @@ public function prepareImportValue($data, $mode, $entry_id = null)
public function getExportModes()
{
return array(
'getPostdata' => ExportableField::POSTDATA,
'listEntry' => ExportableField::LIST_OF
'getPostdata' => ExportableField::POSTDATA,
'listEntry' => ExportableField::LIST_OF
+ ExportableField::ENTRY,
'listEntryObject' => ExportableField::LIST_OF
'listEntryObject' => ExportableField::LIST_OF
+ ExportableField::ENTRY
+ ExportableField::OBJECT,
'listEntryToValue' => ExportableField::LIST_OF
'listEntryToValue' => ExportableField::LIST_OF
+ ExportableField::ENTRY
+ ExportableField::VALUE,
'listValue' => ExportableField::LIST_OF
'listValue' => ExportableField::LIST_OF
+ ExportableField::VALUE
);
}
Expand Down

0 comments on commit c3da800

Please sign in to comment.