public function getEntryTableAttributeHtml(EntryModel $entry, $attribute) { // If custom field, get field handle if (strncmp($attribute, 'field:', 6) === 0) { $fieldId = substr($attribute, 6); $field = craft()->fields->getFieldById($fieldId); $attribute = $field->handle; } $attributes = $entry->getAttributes(); if ($fieldData = craft()->venti_eventManage->getEventFieldData($attributes['id'], $attributes['locale'])) { switch ($attribute) { case 'ventiStartDate': return $fieldData['startDate']->format('M d, Y'); break; case 'ventiEndDate': return $fieldData['endDate']->format('M d, Y'); break; case 'ventiRepeat': return $fieldData['repeat']; break; case 'ventiAllDay': return $fieldData['allDay']; break; case 'ventiRepeatSummary': return $fieldData['summary']; break; } } else { // throw new Exception(Craft::t('Event with id “{id}” in locale “{locale}”. Try resaving events.', array('id' => $attributes['id'], 'locale' => $attributes['locale']))); VentiPlugin::log("Entry table attributes can't be found for Venti attributes.", LogLevel::Error, true); } }
/** * Parse entry fields. * * @param EntryModel $entry * @param bool $empty * * @return array */ public function fields(EntryModel $entry, $empty = false) { // Always save id and title $fields = array('id' => array('label' => Craft::t('ID'), 'value' => $entry->id), 'title' => array('label' => Craft::t('Title'), 'value' => (string) $entry->getTitle()), 'section' => array('label' => Craft::t('Section'), 'value' => (string) $entry->getSection())); // Get element type $elementType = craft()->elements->getElementType(ElementType::Entry); // Get nice attributes $availableAttributes = $elementType->defineAvailableTableAttributes(); // Make 'em fit $attributes = array(); foreach ($availableAttributes as $key => $result) { $attributes[$key] = $result['label']; } // Get static "fields" foreach ($entry->getAttributes() as $handle => $value) { // Only show nice attributes if (array_key_exists($handle, $attributes)) { $fields[$handle] = array('label' => $attributes[$handle], 'value' => StringHelper::arrayToString(is_array($value) ? array_filter(ArrayHelper::flattenArray($value), 'strlen') : $value, ', ')); } } // Get fieldlayout $entrytype = $entry->getType(); if ($entrytype) { $tabs = craft()->fields->getLayoutById($entrytype->fieldLayoutId)->getTabs(); foreach ($tabs as $tab) { foreach ($tab->getFields() as $field) { // Get field values $field = $field->getField(); $handle = $field->handle; $label = $field->name; $value = $empty ? '' : craft()->auditLog->parseFieldData($handle, $entry->{$handle}); // Set on fields $fields[$handle] = array('label' => $label, 'value' => $value); } } } // Return return $fields; }