/** * @inheritDoc IElementType::getTableAttributeHtml() * * @param BaseElementModel $element * @param string $attribute * * @return mixed|string */ public function getTableAttributeHtml(BaseElementModel $element, $attribute) { switch ($attribute) { case 'link': $url = $element->getUrl(); if ($url) { return '<a href="' . $url . '" target="_blank" data-icon="world" title="' . Craft::t('Visit webpage') . '"></a>'; } else { return ''; } case 'uri': $url = $element->getUrl(); if ($url) { $value = $element->uri; if ($value == '__home__') { $value = '<span data-icon="home" title="' . Craft::t('Homepage') . '"></span>'; } else { // Add some <wbr> tags in there so it doesn't all have to be on one line $find = array('/'); $replace = array('/<wbr>'); $wordSeparator = craft()->config->get('slugWordSeparator'); if ($wordSeparator) { $find[] = $wordSeparator; $replace[] = $wordSeparator . '<wbr>'; } $value = str_replace($find, $replace, $value); } return '<a href="' . $url . '" target="_blank" class="go" title="' . Craft::t('Visit webpage') . '"><span dir="ltr">' . $value . '</span></a>'; } else { return ''; } default: // Is this a custom field? if (preg_match('/^field:(\\d+)$/', $attribute, $matches)) { $fieldId = $matches[1]; $field = craft()->fields->getFieldById($fieldId); if ($field) { $fieldType = $field->getFieldType(); if ($fieldType && $fieldType instanceof IPreviewableFieldType) { // Was this field value eager-loaded? if ($fieldType instanceof IEagerLoadingFieldType && $element->hasEagerLoadedElements($field->handle)) { $value = $element->getEagerLoadedElements($field->handle); } else { $value = $element->getFieldValue($field->handle); } $fieldType->setElement($element); return $fieldType->getTableAttributeHtml($value); } } return ''; } $value = $element->{$attribute}; if ($value instanceof DateTime) { return '<span title="' . $value->localeDate() . ' ' . $value->localeTime() . '">' . $value->uiTimestamp() . '</span>'; } return HtmlHelper::encode($value); } }
/** * Updates the search indexes based on the new content values. * * @param BaseElementModel $element * @param ContentModel $content * @param FieldLayoutModel $fieldLayout * @param array|null &$nonTranslatableFields * @param array|null &$otherContentModels * * @return null */ private function _updateSearchIndexes(BaseElementModel $element, ContentModel $content, FieldLayoutModel $fieldLayout, &$nonTranslatableFields = null, &$otherContentModels = null) { $searchKeywordsByLocale = array(); foreach ($fieldLayout->getFields() as $fieldLayoutField) { $field = $fieldLayoutField->getField(); if ($field) { $fieldType = $field->getFieldType(); if ($fieldType) { $fieldType->element = $element; $handle = $field->handle; // Set the keywords for the content's locale $fieldSearchKeywords = $fieldType->getSearchKeywords($element->getFieldValue($handle)); $searchKeywordsByLocale[$content->locale][$field->id] = $fieldSearchKeywords; // Should we queue up the other locales' new keywords too? if (isset($nonTranslatableFields[$field->id])) { foreach ($otherContentModels as $otherContentModel) { $searchKeywordsByLocale[$otherContentModel->locale][$field->id] = $fieldSearchKeywords; } } } } } foreach ($searchKeywordsByLocale as $localeId => $keywords) { craft()->search->indexElementFields($element->id, $localeId, $keywords); } }