12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299 |
- <?php
- /**
- * @file
- * Definition of views_plugin_display.
- */
- /**
- * @defgroup views_display_plugins Views display plugins
- * @{
- * Display plugins control how Views interact with the rest of Drupal.
- *
- * They can handle creating Views from a Drupal page hook; they can
- * handle creating Views from a Drupal block hook. They can also
- * handle creating Views from an external module source, such as
- * a Panels pane, or an insert view, or a CCK field type.
- *
- * @see hook_views_plugins()
- */
- /**
- * The default display plugin handler. Display plugins handle options and
- * basic mechanisms for different output methods.
- */
- class views_plugin_display extends views_plugin {
- /**
- * The top object of a view.
- *
- * @var view
- */
- public $view = NULL;
- /**
- * List of handlers for this display.
- *
- * @var array
- */
- public $handlers = array();
- /**
- * Stores all available display extenders.
- *
- * @var array
- */
- public $extender = array();
- /**
- * {@inheritdoc}
- */
- public function init(&$view, &$display, $options = NULL) {
- $this->view = &$view;
- $this->display = &$display;
- // Load extenders as soon as possible.
- $this->extender = array();
- $extenders = views_get_enabled_display_extenders();
- // If you update to the dev version the registry might not be loaded yet.
- if (!empty($extenders) && class_exists('views_plugin_display_extender')) {
- foreach ($extenders as $extender) {
- $plugin = views_get_plugin('display_extender', $extender);
- if ($plugin) {
- $plugin->init($this->view, $this);
- $this->extender[$extender] = $plugin;
- }
- else {
- vpr('Invalid display extender @extender', array('@extender' => $extender));
- }
- }
- }
- // Track changes that the user should know about.
- $changed = FALSE;
- // Make some modifications.
- if (!isset($options) && isset($display->display_options)) {
- $options = $display->display_options;
- }
- if ($this->is_default_display() && isset($options['defaults'])) {
- unset($options['defaults']);
- }
- // Cache for unpack_options, but not if we are in the ui.
- static $unpack_options = array();
- if (empty($view->editing)) {
- $cid = 'unpack_options:' . md5(serialize(array($this->options, $options)));
- if (empty($unpack_options[$cid])) {
- $cache = views_cache_get($cid, TRUE);
- if (!empty($cache->data)) {
- $this->options = $cache->data;
- }
- else {
- $this->unpack_options($this->options, $options);
- views_cache_set($cid, $this->options, TRUE);
- }
- $unpack_options[$cid] = $this->options;
- }
- else {
- $this->options = $unpack_options[$cid];
- }
- }
- else {
- $this->unpack_options($this->options, $options);
- }
- // Translate changed settings.
- $items_per_page = $this->get_option('items_per_page');
- $offset = $this->get_option('offset');
- $use_pager = $this->get_option('use_pager');
- $pager = $this->get_option('pager');
- // Check if the pager options were already converted.
- // The pager settings of a Views 2.x view specifying 10 items with an
- // offset of 0 and no pager is the same as of a Views 3.x view with
- // default settings. In this case, the only way to determine which case we
- // are dealing with is checking the API version but that's only available
- // for exported Views as it's not stored in the database.
- // If you would like to change this code, really take care that you thought
- // of every possibility.
- // @todo Provide a way to convert the database views as well.
- if (((!empty($items_per_page) && $items_per_page != 10) || !empty($offset) || !empty($use_pager))
- || (!empty($view->api_version) && $view->api_version == 2)) {
- // Find out the right pager type.
- // If the view "use pager" it's a normal/full pager.
- if ($use_pager) {
- $type = 'full';
- }
- // If it does not use pager, but 0 items per page it should not page
- // else it should display just a certain amount of items.
- else {
- $type = $items_per_page ? 'some' : 'none';
- }
- // Setup the pager options.
- $pager = array(
- 'type' => $type,
- 'options' => array(
- 'offset' => intval($offset),
- ),
- );
- if ($items_per_page) {
- $pager['options']['items_per_page'] = $items_per_page;
- }
- // Setup the pager element.
- if ($id = $this->get_option('pager_element')) {
- $pager['options']['id'] = $id;
- }
- // Unset the previous options. After edit and save the view they will be
- // erased.
- $this->set_option('items_per_page', NULL);
- $this->set_option('offset', NULL);
- $this->set_option('use_pager', NULL);
- $this->set_option('pager', $pager);
- $changed = TRUE;
- }
- // Plugable headers, footer and empty texts are not compatible with
- // previous version of views. This code converts old values into a
- // configured handler for each area.
- foreach (array('header', 'footer', 'empty') as $area) {
- $converted = FALSE;
- if (isset($this->options[$area]) && !is_array($this->options[$area])) {
- if (!empty($this->options[$area])) {
- $content = $this->get_option($area);
- if (!empty($content) && !is_array($content)) {
- $format = $this->get_option($area . '_format');
- $options = array(
- 'id' => 'area',
- 'table' => 'views',
- 'field' => 'area',
- 'label' => '',
- 'relationship' => 'none',
- 'group_type' => 'group',
- 'content' => $content,
- 'format' => !empty($format) ? $format : filter_default_format(),
- );
- if ($area != 'empty' && $empty = $this->get_option($area . '_empty')) {
- $options['empty'] = $empty;
- }
- $this->set_option($area, array('text' => $options));
- $converted = TRUE;
- $changed = TRUE;
- }
- }
- // Ensure that options are at least an empty array.
- if (!$converted) {
- $this->set_option($area, array());
- }
- }
- }
- // Convert distinct setting from display to query settings.
- $distinct = $this->get_option('distinct');
- if (!empty($distinct)) {
- $query_settings = $this->get_option('query');
- $query_settings['options']['distinct'] = $distinct;
- $this->set_option('query', $query_settings);
- // Clear the values.
- $this->set_option('distinct', NULL);
- $changed = TRUE;
- }
- // Convert field language settings.
- $query_options = $this->get_option('query');
- if (isset($query_options['options']['field_language'])) {
- $this->set_option('field_language', $query_options['options']['field_language']);
- unset($query_options['options']['field_language']);
- $changed = TRUE;
- }
- if (isset($query_options['options']['field_language_add_to_query'])) {
- $this->set_option('field_language_add_to_query', $query_options['options']['field_language_add_to_query']);
- unset($query_options['options']['field_language_add_to_query']);
- $changed = TRUE;
- }
- $this->set_option('query', $query_options);
- // Convert filter groups.
- $filter_groups = $this->get_option('filter_groups');
- // Only convert if it wasn't converted yet, which is the case if there is a
- // '0' group.
- if (isset($filter_groups['groups'][0])) {
- // Update filter groups.
- $filter_groups['groups'] = views_array_key_plus($filter_groups['groups']);
- $this->set_option('filter_groups', $filter_groups);
- // Update the filter group on each filter.
- $filters = $this->get_option('filters');
- foreach ($filters as &$filter) {
- if (isset($filter['group'])) {
- $filter['group']++;
- }
- else {
- $filter['group'] = 1;
- }
- }
- $this->set_option('filters', $filters);
- $changed = TRUE;
- }
- // Filter groups were allowed to be rewritten without its filters, so
- // before this update the view was using the default values. To be sure that
- // the existing view isn't broken, don't use this overridden values but copy
- // them from the default display. Only do this if the filters are overridden
- // but the filter_groups are not marked as so.
- if (!$this->is_default_display() && !$this->options['defaults']['filters'] && $this->options['defaults']['filter_groups']) {
- // Set filter_groups to be overridden and save the value in the
- // display_options as well.
- $this->options['defaults']['filter_groups'] = FALSE;
- $this->display->display_options['defaults']['filter_groups'] = $this->options['defaults']['filter_groups'];
- // Copy the filter_groups from the default, and add them to the
- // display_options as well. $this->default_display is not initialized at
- // this point.
- $this->options['filter_groups'] = $this->view->display['default']->handler->options['filter_groups'];
- $this->display->display_options['filter_groups'] = $this->options['filter_groups'];
- $changed = TRUE;
- }
- // Mark the view as changed so the user has a chance to save it.
- if ($changed) {
- $this->view->changed = TRUE;
- }
- }
- /**
- * {@inheritdoc}
- */
- public function destroy() {
- parent::destroy();
- foreach ($this->handlers as $type => $handlers) {
- foreach ($handlers as $id => $handler) {
- if (is_object($handler)) {
- $this->handlers[$type][$id]->destroy();
- }
- }
- }
- if (isset($this->default_display)) {
- unset($this->default_display);
- }
- foreach ($this->extender as $extender) {
- $extender->destroy();
- }
- }
- /**
- * If this display is the 'default' display which contains fallback settings.
- *
- * @return bool
- * This is the default display and contains fallback settings.
- */
- public function is_default_display() {
- return FALSE;
- }
- /**
- * Does this display uses exposed filters?
- *
- * So the view will know whether or not to build them.
- */
- public function uses_exposed() {
- if (!isset($this->has_exposed)) {
- foreach ($this->handlers as $type => $value) {
- foreach ($this->view->$type as $id => $handler) {
- if ($handler->can_expose() && $handler->is_exposed()) {
- // one is all we need; if we find it, return true.
- $this->has_exposed = TRUE;
- return TRUE;
- }
- }
- }
- $pager = $this->get_plugin('pager');
- if (isset($pager) && $pager->uses_exposed()) {
- $this->has_exposed = TRUE;
- return TRUE;
- }
- $this->has_exposed = FALSE;
- }
- return $this->has_exposed;
- }
- /**
- * Determine if this display should display the exposed filters widgets.
- *
- * If so, the view will know whether or not to render them.
- *
- * Regardless of what this function returns, exposed filters will not be used
- * nor displayed unless uses_exposed() returns TRUE.
- */
- public function displays_exposed() {
- return TRUE;
- }
- /**
- * Does the display use AJAX?
- */
- public function use_ajax() {
- if (!empty($this->definition['use ajax'])) {
- return $this->get_option('use_ajax');
- }
- return FALSE;
- }
- /**
- * Does the display have a pager enabled?
- */
- public function use_pager() {
- $pager = $this->get_plugin('pager');
- if ($pager) {
- return $pager->use_pager();
- }
- }
- /**
- * Does the display have a more link enabled?
- */
- public function use_more() {
- if (!empty($this->definition['use more'])) {
- return $this->get_option('use_more');
- }
- return FALSE;
- }
- /**
- * Does the display have groupby enabled?
- */
- public function use_group_by() {
- return $this->get_option('group_by');
- }
- /**
- * Should the enabled display more link be shown when no more items?
- */
- public function use_more_always() {
- if (!empty($this->definition['use more'])) {
- return $this->get_option('use_more_always');
- }
- return FALSE;
- }
- /**
- * Should the enabled display more link being opened in an new window?
- */
- public function use_more_open_new_window() {
- if (!empty($this->definition['use more'])) {
- return $this->get_option('open_new_window');
- }
- return FALSE;
- }
- /**
- * Does the display have custom link text?
- */
- public function use_more_text() {
- if (!empty($this->definition['use more'])) {
- return $this->get_option('use_more_text');
- }
- return FALSE;
- }
- /**
- * Can this display accept attachments?
- */
- public function accept_attachments() {
- if (empty($this->definition['accept attachments'])) {
- return FALSE;
- }
- if (!empty($this->view->argument) && $this->get_option('hide_attachment_summary')) {
- foreach ($this->view->argument as $argument_id => $argument) {
- if ($argument->needs_style_plugin() && empty($argument->argument_validated)) {
- return FALSE;
- }
- }
- }
- return TRUE;
- }
- /**
- * Allow displays to attach to other views.
- */
- public function attach_to($display_id) {
- }
- /**
- * List which sections are defaultable and what items each section contains.
- */
- public function defaultable_sections($section = NULL) {
- $sections = array(
- 'access' => array('access', 'access_options'),
- 'access_options' => array('access', 'access_options'),
- 'cache' => array('cache', 'cache_options'),
- 'cache_options' => array('cache', 'cache_options'),
- 'title' => array('title'),
- 'css_class' => array('css_class'),
- 'use_ajax' => array('use_ajax'),
- 'hide_attachment_summary' => array('hide_attachment_summary'),
- 'hide_admin_links' => array('hide_admin_links'),
- 'group_by' => array('group_by'),
- 'query' => array('query'),
- 'use_more' => array('use_more',
- 'use_more_always',
- 'open_new_window',
- 'use_more_text',
- ),
- 'use_more_always' => array(
- 'use_more',
- 'use_more_always',
- 'open_new_window',
- 'use_more_text',
- ),
- 'use_more_text' => array(
- 'use_more',
- 'use_more_always',
- 'open_new_window',
- 'use_more_text',
- ),
- 'open_new_window' => array(
- 'use_more',
- 'use_more_always',
- 'open_new_window',
- 'use_more_text',
- ),
- 'link_display' => array('link_display', 'link_url'),
- // Force these to cascade properly.
- 'style_plugin' => array(
- 'style_plugin',
- 'style_options',
- 'row_plugin',
- 'row_options',
- ),
- 'style_options' => array(
- 'style_plugin',
- 'style_options',
- 'row_plugin',
- 'row_options',
- ),
- 'row_plugin' => array(
- 'style_plugin',
- 'style_options',
- 'row_plugin',
- 'row_options',
- ),
- 'row_options' => array(
- 'style_plugin',
- 'style_options',
- 'row_plugin',
- 'row_options',
- ),
- 'pager' => array('pager', 'pager_options'),
- 'pager_options' => array('pager', 'pager_options'),
- 'exposed_form' => array('exposed_form', 'exposed_form_options'),
- 'exposed_form_options' => array('exposed_form', 'exposed_form_options'),
- // These guys are special.
- 'header' => array('header'),
- 'footer' => array('footer'),
- 'empty' => array('empty'),
- 'relationships' => array('relationships'),
- 'fields' => array('fields'),
- 'sorts' => array('sorts'),
- 'arguments' => array('arguments'),
- 'filters' => array('filters', 'filter_groups'),
- 'filter_groups' => array('filters', 'filter_groups'),
- );
- // If the display cannot use a pager, then we cannot default it.
- if (empty($this->definition['use pager'])) {
- unset($sections['pager']);
- unset($sections['items_per_page']);
- }
- foreach ($this->extender as $extender) {
- $extender->defaultable_sections($sections, $section);
- }
- if ($section) {
- if (!empty($sections[$section])) {
- return $sections[$section];
- }
- }
- else {
- return $sections;
- }
- }
- /**
- * {@inheritdoc}
- */
- public function option_definition() {
- $options = array(
- 'defaults' => array(
- 'default' => array(
- 'access' => TRUE,
- 'cache' => TRUE,
- 'query' => TRUE,
- 'title' => TRUE,
- 'css_class' => TRUE,
- 'display_description' => FALSE,
- 'use_ajax' => TRUE,
- 'hide_attachment_summary' => TRUE,
- 'hide_admin_links' => TRUE,
- 'pager' => TRUE,
- 'pager_options' => TRUE,
- 'use_more' => TRUE,
- 'use_more_always' => TRUE,
- 'open_new_window' => FALSE,
- 'use_more_text' => TRUE,
- 'exposed_form' => TRUE,
- 'exposed_form_options' => TRUE,
- 'link_display' => TRUE,
- 'link_url' => '',
- 'group_by' => TRUE,
- 'style_plugin' => TRUE,
- 'style_options' => TRUE,
- 'row_plugin' => TRUE,
- 'row_options' => TRUE,
- 'header' => TRUE,
- 'footer' => TRUE,
- 'empty' => TRUE,
- 'relationships' => TRUE,
- 'fields' => TRUE,
- 'sorts' => TRUE,
- 'arguments' => TRUE,
- 'filters' => TRUE,
- 'filter_groups' => TRUE,
- ),
- 'export' => FALSE,
- ),
- 'title' => array(
- 'default' => '',
- 'translatable' => TRUE,
- ),
- 'enabled' => array(
- 'default' => TRUE,
- 'translatable' => FALSE,
- 'bool' => TRUE,
- ),
- 'display_comment' => array(
- 'default' => '',
- ),
- 'css_class' => array(
- 'default' => '',
- 'translatable' => FALSE,
- ),
- 'display_description' => array(
- 'default' => '',
- 'translatable' => TRUE,
- ),
- 'use_ajax' => array(
- 'default' => FALSE,
- 'bool' => TRUE,
- ),
- 'hide_attachment_summary' => array(
- 'default' => FALSE,
- 'bool' => TRUE,
- ),
- 'hide_admin_links' => array(
- 'default' => FALSE,
- 'bool' => TRUE,
- ),
- // This is legacy code.
- // Items_per/offset/use_pager is moved to the pager plugin but the
- // automatic update path needs this items defined, so don't remove it.
- // @see views_plugin_display::init()
- 'items_per_page' => array(
- 'default' => 10,
- ),
- 'offset' => array(
- 'default' => 0,
- ),
- 'use_pager' => array(
- 'default' => FALSE,
- 'bool' => TRUE,
- ),
- 'use_more' => array(
- 'default' => FALSE,
- 'bool' => TRUE,
- ),
- 'use_more_always' => array(
- 'default' => FALSE,
- 'bool' => TRUE,
- 'export' => 'export_option_always',
- ),
- 'use_more_text' => array(
- 'default' => 'more',
- 'translatable' => TRUE,
- ),
- 'link_display' => array(
- 'default' => '',
- ),
- 'link_url' => array(
- 'default' => '',
- ),
- 'group_by' => array(
- 'default' => FALSE,
- 'bool' => TRUE,
- ),
- 'field_language' => array(
- 'default' => '***CURRENT_LANGUAGE***',
- ),
- 'field_language_add_to_query' => array(
- 'default' => 1,
- ),
- // These types are all plugins that can have individual settings and
- // therefore need special handling.
- 'access' => array(
- 'contains' => array(
- 'type' => array(
- 'default' => 'none',
- 'export' => 'export_plugin',
- 'unpack_translatable' => 'unpack_plugin',
- ),
- ),
- ),
- 'cache' => array(
- 'contains' => array(
- 'type' => array(
- 'default' => 'none',
- 'export' => 'export_plugin',
- 'unpack_translatable' => 'unpack_plugin',
- ),
- ),
- ),
- 'query' => array(
- 'contains' => array(
- 'type' => array(
- 'default' => 'views_query',
- 'export' => 'export_plugin',
- ),
- 'options' => array('default' => array(), 'export' => FALSE),
- ),
- ),
- // Note that exposed_form plugin has options in a separate array, while
- // access and cache do not. access and cache are legacy and that pattern
- // should not be repeated, but it is left as is to reduce the need to
- // modify older views. Let's consider the pattern used here to be the
- // template from which future plugins should be copied.
- 'exposed_form' => array(
- 'contains' => array(
- 'type' => array(
- 'default' => 'basic',
- 'export' => 'export_plugin',
- 'unpack_translatable' => 'unpack_plugin',
- ),
- 'options' => array('default' => array(), 'export' => FALSE),
- ),
- ),
- 'pager' => array(
- 'contains' => array(
- 'type' => array(
- 'default' => 'full',
- 'export' => 'export_plugin',
- 'unpack_translatable' => 'unpack_plugin',
- ),
- 'options' => array('default' => array(), 'export' => FALSE),
- ),
- ),
- // Note that the styles have their options completely independent. Like
- // access and cache above, this is a legacy pattern and should not be
- // repeated.
- 'style_plugin' => array(
- 'default' => 'default',
- 'export' => 'export_style',
- 'unpack_translatable' => 'unpack_style',
- ),
- 'style_options' => array(
- 'default' => array(),
- 'export' => FALSE,
- ),
- 'row_plugin' => array(
- 'default' => 'fields',
- 'export' => 'export_style',
- 'unpack_translatable' => 'unpack_style',
- ),
- 'row_options' => array(
- 'default' => array(),
- 'export' => FALSE,
- ),
- 'exposed_block' => array(
- 'default' => FALSE,
- ),
- 'header' => array(
- 'default' => array(),
- 'export' => 'export_handler',
- 'unpack_translatable' => 'unpack_handler',
- ),
- 'footer' => array(
- 'default' => array(),
- 'export' => 'export_handler',
- 'unpack_translatable' => 'unpack_handler',
- ),
- 'empty' => array(
- 'default' => array(),
- 'export' => 'export_handler',
- 'unpack_translatable' => 'unpack_handler',
- ),
- // We want these to export last.
- // These are the 5 handler types.
- 'relationships' => array(
- 'default' => array(),
- 'export' => 'export_handler',
- 'unpack_translatable' => 'unpack_handler',
- ),
- 'fields' => array(
- 'default' => array(),
- 'export' => 'export_handler',
- 'unpack_translatable' => 'unpack_handler',
- ),
- 'sorts' => array(
- 'default' => array(),
- 'export' => 'export_handler',
- 'unpack_translatable' => 'unpack_handler',
- ),
- 'arguments' => array(
- 'default' => array(),
- 'export' => 'export_handler',
- 'unpack_translatable' => 'unpack_handler',
- ),
- 'filter_groups' => array(
- 'contains' => array(
- 'operator' => array('default' => 'AND'),
- 'groups' => array('default' => array(1 => 'AND')),
- ),
- ),
- 'filters' => array(
- 'default' => array(),
- 'export' => 'export_handler',
- 'unpack_translatable' => 'unpack_handler',
- ),
- );
- if (empty($this->definition['use pager'])) {
- $options['defaults']['default']['use_pager'] = FALSE;
- $options['defaults']['default']['items_per_page'] = FALSE;
- $options['defaults']['default']['offset'] = FALSE;
- $options['defaults']['default']['pager'] = FALSE;
- $options['pager']['contains']['type']['default'] = 'some';
- }
- if ($this->is_default_display()) {
- unset($options['defaults']);
- }
- foreach ($this->extender as $extender) {
- $extender->options_definition_alter($options);
- }
- return $options;
- }
- /**
- * Check to see if the display has a 'path' field.
- *
- * This is a pure function and not just a setting on the definition
- * because some displays (such as a panel pane) may have a path based
- * upon configuration.
- *
- * By default, displays do not have a path.
- */
- public function has_path() {
- return FALSE;
- }
- /**
- * Check to see if the display has some need to link to another display.
- *
- * For the most part, displays without a path will use a link display.
- * However, sometimes displays that have a path might also need to link to
- * another display. This is true for feeds.
- */
- public function uses_link_display() {
- return !$this->has_path();
- }
- /**
- * Check to see if the display can put the exposed form in a block.
- *
- * By default, displays that do not have a path cannot disconnect the exposed
- * form and put it in a block, because the form has no place to go and Views
- * really wants the forms to go to a specific page.
- */
- public function uses_exposed_form_in_block() {
- return $this->has_path();
- }
- /**
- * Check to see which display to use when creating links.
- */
- public function get_link_display() {
- $display_id = $this->get_option('link_display');
- // If unknown, pick the first one.
- if (empty($display_id) || empty($this->view->display[$display_id])) {
- foreach ($this->view->display as $display_id => $display) {
- if (!empty($display->handler) && $display->handler->has_path()) {
- return $display_id;
- }
- }
- }
- else {
- return $display_id;
- }
- // Fall-through returns NULL.
- }
- /**
- * Return the base path to use for this display.
- *
- * This can be overridden for displays that do strange things with the path.
- */
- public function get_path() {
- if ($this->has_path()) {
- return $this->get_option('path');
- }
- $display_id = $this->get_link_display();
- if ($display_id && !empty($this->view->display[$display_id]) && is_object($this->view->display[$display_id]->handler)) {
- return $this->view->display[$display_id]->handler->get_path();
- }
- if ($this->get_option('link_display') == 'custom_url' && $link_url = $this->get_option('link_url')) {
- return $link_url;
- }
- }
- /**
- *
- */
- public function get_url() {
- return $this->view->get_url();
- }
- /**
- * Check to see if the display needs a breadcrumb.
- *
- * By default, displays do not need breadcrumbs.
- */
- public function uses_breadcrumb() {
- return FALSE;
- }
- /**
- * Determine if a given option is set to use the default or current display.
- *
- * @return
- * TRUE for the default display.
- */
- public function is_defaulted($option) {
- return !$this->is_default_display() && !empty($this->default_display) && !empty($this->options['defaults'][$option]);
- }
- /**
- * Intelligently get an option either from this or default display.
- */
- public function get_option($option) {
- if ($this->is_defaulted($option)) {
- return $this->default_display->get_option($option);
- }
- if (isset($this->options[$option]) || array_key_exists($option, $this->options)) {
- return $this->options[$option];
- }
- }
- /**
- * Determine if the display's style uses fields.
- */
- public function uses_fields() {
- $plugin = $this->get_plugin();
- if ($plugin) {
- return $plugin->uses_fields();
- }
- }
- /**
- * Get the instance of a plugin, for example style or row.
- *
- * @param string $type
- * The type of the plugin.
- * @param string $name
- * The name of the plugin defined in hook_views_plugins.
- *
- * @return views_plugin|FALSE
- * FALSE if no plugin, otherwise the requested instance of a plugin.
- */
- public function get_plugin($type = 'style', $name = NULL) {
- static $cache = array();
- if (!isset($cache[$type][$name])) {
- switch ($type) {
- case 'style':
- case 'row':
- $option_name = $type . '_plugin';
- $options = $this->get_option($type . '_options');
- if (!$name) {
- $name = $this->get_option($option_name);
- }
- break;
- case 'query':
- $views_data = views_fetch_data($this->view->base_table);
- $name = !empty($views_data['table']['base']['query class']) ? $views_data['table']['base']['query class'] : 'views_query';
- default:
- $option_name = $type;
- $options = $this->get_option($type);
- if (!$name) {
- $name = $options['type'];
- }
- // Access & cache store their options as siblings with the type; all
- // others use an 'options' array.
- if ($type != 'access' && $type != 'cache') {
- $options = $options['options'];
- }
- }
- $plugin = views_get_plugin($type, $name);
- if (!$plugin) {
- return FALSE;
- }
- if ($type != 'query') {
- $plugin->init($this->view, $this->display, $options);
- }
- else {
- $display_id = $this->is_defaulted($option_name) ? $this->display->id : 'default';
- $plugin->localization_keys = array($display_id, $type);
- if (!isset($this->base_field)) {
- $views_data = views_fetch_data($this->view->base_table);
- $this->view->base_field = !empty($views_data['table']['base']['field']) ? $views_data['table']['base']['field'] : '';
- }
- $plugin->init($this->view->base_table, $this->view->base_field, $options);
- }
- $cache[$type][$name] = $plugin;
- }
- return $cache[$type][$name];
- }
- /**
- * Get the handler object for a single handler.
- */
- public function &get_handler($type, $id) {
- if (!isset($this->handlers[$type])) {
- $this->get_handlers($type);
- }
- if (isset($this->handlers[$type][$id])) {
- return $this->handlers[$type][$id];
- }
- // So we can return a reference.
- $null = NULL;
- return $null;
- }
- /**
- * Get a full array of handlers for $type. This caches them.
- */
- public function &get_handlers($type) {
- if (!isset($this->handlers[$type])) {
- $this->handlers[$type] = array();
- $types = views_object_types();
- $plural = $types[$type]['plural'];
- foreach ($this->get_option($plural) as $id => $info) {
- // If this is during form submission and there are temporary options
- // which can only appear if the view is in the edit cache, use those
- // options instead. This is used for AJAX multi-step stuff.
- if (isset($_POST['form_id']) && isset($this->view->temporary_options[$type][$id])) {
- $info = $this->view->temporary_options[$type][$id];
- }
- if ($info['id'] != $id) {
- $info['id'] = $id;
- }
- // If aggregation is on, the group type might override the actual
- // handler that is in use. This piece of code checks that and,
- // if necessary, sets the override handler.
- $override = NULL;
- if ($this->use_group_by() && !empty($info['group_type'])) {
- if (empty($this->view->query)) {
- $this->view->init_query();
- }
- $aggregate = $this->view->query->get_aggregation_info();
- if (!empty($aggregate[$info['group_type']]['handler'][$type])) {
- $override = $aggregate[$info['group_type']]['handler'][$type];
- }
- }
- if (!empty($types[$type]['type'])) {
- $handler_type = $types[$type]['type'];
- }
- else {
- $handler_type = $type;
- }
- $handler = views_get_handler($info['table'], $info['field'], $handler_type, $override);
- if ($handler) {
- // Special override for area types so they know where they come from.
- if ($handler_type == 'area') {
- $handler->handler_type = $type;
- }
- $handler->init($this->view, $info);
- $this->handlers[$type][$id] = &$handler;
- }
- // Prevent reference problems.
- unset($handler);
- }
- }
- return $this->handlers[$type];
- }
- /**
- * List of fields for the current display with the associated relationship.
- *
- * @param bool $groupable_only
- * Return only an array of field labels from handler that return TRUE from
- * use_string_group_by method.
- */
- public function get_field_labels() {
- // Use func_get_arg so the function signature isn't amended but we can still
- // pass TRUE into the function to filter by groupable handlers.
- $args = func_get_args();
- $groupable_only = isset($args[0]) ? $args[0] : FALSE;
- $options = array();
- foreach ($this->get_handlers('relationship') as $relationship => $handler) {
- if ($label = $handler->label()) {
- $relationships[$relationship] = $label;
- }
- else {
- $relationships[$relationship] = $handler->ui_name();
- }
- }
- foreach ($this->get_handlers('field') as $id => $handler) {
- if ($groupable_only && !$handler->use_string_group_by()) {
- // Continue to next handler if it's not groupable.
- continue;
- }
- if ($label = $handler->label()) {
- $options[$id] = $label;
- }
- else {
- $options[$id] = $handler->ui_name();
- }
- if (!empty($handler->options['relationship']) && !empty($relationships[$handler->options['relationship']])) {
- $options[$id] = '(' . $relationships[$handler->options['relationship']] . ') ' . $options[$id];
- }
- }
- return $options;
- }
- /**
- * Intelligently set an option either from this display or from the
- * default display, if directed to do so.
- */
- public function set_option($option, $value) {
- if ($this->is_defaulted($option)) {
- return $this->default_display->set_option($option, $value);
- }
- // Set this in two places: On the handler where we'll notice it but also on
- // the display object so it gets saved. This should only be a temporary fix.
- $this->display->display_options[$option] = $value;
- return $this->options[$option] = $value;
- }
- /**
- * Set an option and force it to be an override.
- */
- public function override_option($option, $value) {
- $this->set_override($option, FALSE);
- $this->set_option($option, $value);
- }
- /**
- * Because forms may be split up into sections, this provides
- * an easy URL to exactly the right section. Don't override this.
- */
- public function option_link($text, $section, $class = '', $title = '') {
- views_add_js('ajax');
- if (!empty($class)) {
- $text = '<span>' . $text . '</span>';
- }
- if (!trim($text)) {
- $text = t('Broken field');
- }
- if (empty($title)) {
- $title = $text;
- }
- // Truncate the path as it is displayed as a link.
- if ($section == 'path') {
- $text = views_ui_truncate($text, 24);
- }
- return l($text,
- 'admin/structure/views/nojs/display/' . $this->view->name . '/' . $this->display->id . '/' . $section,
- array(
- 'attributes' => array(
- 'class' => 'views-ajax-link ' . $class,
- 'title' => $title,
- 'id' => drupal_html_id('views-' . $this->display->id . '-' . $section),
- ),
- 'html' => TRUE,
- )
- );
- }
- /**
- * Returns to tokens for arguments.
- *
- * This function is similar to views_handler_field::get_render_tokens() but
- * without fields tokens.
- */
- public function get_arguments_tokens() {
- $tokens = array();
- if (!empty($this->view->build_info['substitutions'])) {
- $tokens = $this->view->build_info['substitutions'];
- }
- $count = 0;
- foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
- $token = '%' . ++$count;
- if (!isset($tokens[$token])) {
- $tokens[$token] = '';
- }
- // Use strip tags as there should never be HTML in the path.
- // However, we need to preserve special characters like " that
- // were removed by check_plain().
- $tokens['!' . $count] = isset($this->view->args[$count - 1]) ? strip_tags(decode_entities($this->view->args[$count - 1])) : '';
- }
- return $tokens;
- }
- /**
- * Provide the default summary for options in the views UI.
- *
- * This output is returned as an array.
- */
- public function options_summary(&$categories, &$options) {
- $categories = array(
- 'title' => array(
- 'title' => t('Title'),
- 'column' => 'first',
- ),
- 'format' => array(
- 'title' => t('Format'),
- 'column' => 'first',
- ),
- 'filters' => array(
- 'title' => t('Filters'),
- 'column' => 'first',
- ),
- 'fields' => array(
- 'title' => t('Fields'),
- 'column' => 'first',
- ),
- 'pager' => array(
- 'title' => t('Pager'),
- 'column' => 'second',
- ),
- 'exposed' => array(
- 'title' => t('Exposed form'),
- 'column' => 'third',
- 'build' => array(
- '#weight' => 1,
- ),
- ),
- 'access' => array(
- 'title' => '',
- 'column' => 'second',
- 'build' => array(
- '#weight' => -5,
- ),
- ),
- 'other' => array(
- 'title' => t('Other'),
- 'column' => 'third',
- 'build' => array(
- '#weight' => 2,
- ),
- ),
- );
- if ($this->display->id != 'default') {
- $options['display_id'] = array(
- 'category' => 'other',
- 'title' => t('Machine Name'),
- 'value' => !empty($this->display->new_id) ? check_plain($this->display->new_id) : check_plain($this->display->id),
- 'desc' => t('Change the machine name of this display.'),
- );
- }
- $display_comment = check_plain(views_ui_truncate($this->get_option('display_comment'), 80));
- $options['display_comment'] = array(
- 'category' => 'other',
- 'title' => t('Comment'),
- 'value' => !empty($display_comment) ? $display_comment : t('No comment'),
- 'desc' => t('Comment or document this display.'),
- );
- $title = strip_tags($this->get_option('title'));
- if (!$title) {
- $title = t('None');
- }
- $options['title'] = array(
- 'category' => 'title',
- 'title' => t('Title'),
- 'value' => $title,
- 'desc' => t('Change the title that this display will use.'),
- );
- $style_plugin = views_fetch_plugin_data('style', $this->get_option('style_plugin'));
- $style_plugin_instance = $this->get_plugin('style');
- $style_summary = empty($style_plugin['title']) ? t('Missing style plugin') : $style_plugin_instance->summary_title();
- $style_title = empty($style_plugin['title']) ? t('Missing style plugin') : $style_plugin_instance->plugin_title();
- $style = '';
- $options['style_plugin'] = array(
- 'category' => 'format',
- 'title' => t('Format'),
- 'value' => $style_title,
- 'setting' => $style_summary,
- 'desc' => t('Change the way content is formatted.'),
- );
- // This adds a 'Settings' link to the style_options setting if the style
- // has options.
- if (!empty($style_plugin['uses options'])) {
- $options['style_plugin']['links']['style_options'] = t('Change settings for this format');
- }
- if (!empty($style_plugin['uses row plugin'])) {
- $row_plugin = views_fetch_plugin_data('row', $this->get_option('row_plugin'));
- $row_plugin_instance = $this->get_plugin('row');
- $row_summary = empty($row_plugin['title']) ? t('Missing style plugin') : $row_plugin_instance->summary_title();
- $row_title = empty($row_plugin['title']) ? t('Missing style plugin') : $row_plugin_instance->plugin_title();
- $options['row_plugin'] = array(
- 'category' => 'format',
- 'title' => t('Show'),
- 'value' => $row_title,
- 'setting' => $row_summary,
- 'desc' => t('Change the way each row in the view is styled.'),
- );
- // This adds a 'Settings' link to the row_options setting if the row
- // style has options.
- if (!empty($row_plugin['uses options'])) {
- $options['row_plugin']['links']['row_options'] = t('Change settings for this style');
- }
- }
- if (!empty($this->definition['use ajax'])) {
- $options['use_ajax'] = array(
- 'category' => 'other',
- 'title' => t('Use AJAX'),
- 'value' => $this->get_option('use_ajax') ? t('Yes') : t('No'),
- 'desc' => t('Change whether or not this display will use AJAX.'),
- );
- }
- if (!empty($this->definition['accept attachments'])) {
- $options['hide_attachment_summary'] = array(
- 'category' => 'other',
- 'title' => t('Hide attachments in summary'),
- 'value' => $this->get_option('hide_attachment_summary') ? t('Yes') : t('No'),
- 'desc' => t('Change whether or not to display attachments when displaying a contextual filter summary.'),
- );
- }
- if (!isset($this->definition['contextual links locations']) || !empty($this->definition['contextual links locations'])) {
- $options['hide_admin_links'] = array(
- 'category' => 'other',
- 'title' => t('Hide contextual links'),
- 'value' => $this->get_option('hide_admin_links') ? t('Yes') : t('No'),
- 'desc' => t('Change whether or not to display contextual links for this view.'),
- );
- }
- $pager_plugin = $this->get_plugin('pager');
- if (!$pager_plugin) {
- // Default to the no pager plugin.
- $pager_plugin = views_get_plugin('pager', 'none');
- }
- $pager_str = $pager_plugin->summary_title();
- $options['pager'] = array(
- 'category' => 'pager',
- 'title' => t('Use pager'),
- 'value' => $pager_plugin->plugin_title(),
- 'setting' => $pager_str,
- 'desc' => t("Change this display's pager setting."),
- );
- // If pagers aren't allowed, change the text of the item.
- if (empty($this->definition['use pager'])) {
- $options['pager']['title'] = t('Items to display');
- }
- if (!empty($pager_plugin->definition['uses options'])) {
- $options['pager']['links']['pager_options'] = t('Change settings for this pager type.');
- }
- if (!empty($this->definition['use more'])) {
- $options['use_more'] = array(
- 'category' => 'pager',
- 'title' => t('More link'),
- 'value' => $this->get_option('use_more') ? t('Yes') : t('No'),
- 'desc' => t('Specify whether this display will provide a "more" link.'),
- );
- }
- $this->view->init_query();
- if ($this->view->query->get_aggregation_info()) {
- $options['group_by'] = array(
- 'category' => 'other',
- 'title' => t('Use aggregation'),
- 'value' => $this->get_option('group_by') ? t('Yes') : t('No'),
- 'desc' => t('Allow grouping and aggregation (calculation) of fields.'),
- );
- }
- $options['query'] = array(
- 'category' => 'other',
- 'title' => t('Query settings'),
- 'value' => t('Settings'),
- 'desc' => t('Allow to set some advanced settings for the query plugin'),
- );
- $languages = array(
- '***CURRENT_LANGUAGE***' => t("Current user's language"),
- '***DEFAULT_LANGUAGE***' => t("Default site language"),
- LANGUAGE_NONE => t('Language neutral'),
- );
- if (module_exists('locale')) {
- $languages = array_merge($languages, locale_language_list());
- }
- $field_language = array();
- $options['field_language'] = array(
- 'category' => 'other',
- 'title' => t('Field Language'),
- 'value' => $languages[$this->get_option('field_language')],
- 'desc' => t('All fields which support translations will be displayed in the selected language.'),
- );
- $access_plugin = $this->get_plugin('access');
- if (!$access_plugin) {
- // Default to the no access control plugin.
- $access_plugin = views_get_plugin('access', 'none');
- }
- $access_str = $access_plugin->summary_title();
- $options['access'] = array(
- 'category' => 'access',
- 'title' => t('Access'),
- 'value' => $access_plugin->plugin_title(),
- 'setting' => $access_str,
- 'desc' => t('Specify access control type for this display.'),
- );
- if (!empty($access_plugin->definition['uses options'])) {
- $options['access']['links']['access_options'] = t('Change settings for this access type.');
- }
- $cache_plugin = $this->get_plugin('cache');
- if (!$cache_plugin) {
- // Default to the no cache control plugin.
- $cache_plugin = views_get_plugin('cache', 'none');
- }
- $cache_str = $cache_plugin->summary_title();
- $options['cache'] = array(
- 'category' => 'other',
- 'title' => t('Caching'),
- 'value' => $cache_plugin->plugin_title(),
- 'setting' => $cache_str,
- 'desc' => t('Specify caching type for this display.'),
- );
- if (!empty($cache_plugin->definition['uses options'])) {
- $options['cache']['links']['cache_options'] = t('Change settings for this caching type.');
- }
- if (!empty($access_plugin->definition['uses options'])) {
- $options['access']['links']['access_options'] = t('Change settings for this access type.');
- }
- if ($this->uses_link_display()) {
- $display_id = $this->get_link_display();
- $link_display = empty($this->view->display[$display_id]) ? t('None') : check_plain($this->view->display[$display_id]->display_title);
- $link_display = $this->get_option('link_display') == 'custom_url' ? t('Custom URL') : $link_display;
- $options['link_display'] = array(
- 'category' => 'other',
- 'title' => t('Link display'),
- 'value' => $link_display,
- 'desc' => t('Specify which display or custom url this display will link to.'),
- );
- }
- if ($this->uses_exposed_form_in_block()) {
- $options['exposed_block'] = array(
- 'category' => 'exposed',
- 'title' => t('Exposed form in block'),
- 'value' => $this->get_option('exposed_block') ? t('Yes') : t('No'),
- 'desc' => t('Allow the exposed form to appear in a block instead of the view.'),
- );
- }
- $exposed_form_plugin = $this->get_plugin('exposed_form');
- if (!$exposed_form_plugin) {
- // Default to the no cache control plugin.
- $exposed_form_plugin = views_get_plugin('exposed_form', 'basic');
- }
- $exposed_form_str = $exposed_form_plugin->summary_title();
- $options['exposed_form'] = array(
- 'category' => 'exposed',
- 'title' => t('Exposed form style'),
- 'value' => $exposed_form_plugin->plugin_title(),
- 'setting' => $exposed_form_str,
- 'desc' => t('Select the kind of exposed filter to use.'),
- );
- if (!empty($exposed_form_plugin->definition['uses options'])) {
- $options['exposed_form']['links']['exposed_form_options'] = t('Exposed form settings for this exposed form style.');
- }
- $css_class = check_plain(trim($this->get_option('css_class')));
- if (!$css_class) {
- $css_class = t('None');
- }
- $options['css_class'] = array(
- 'category' => 'other',
- 'title' => t('CSS class'),
- 'value' => $css_class,
- 'desc' => t('Change the CSS class name(s) that will be added to this display.'),
- );
- $options['analyze-theme'] = array(
- 'category' => 'other',
- 'title' => t('Theme'),
- 'value' => t('Information'),
- 'desc' => t('Get information on how to theme this display'),
- );
- foreach ($this->extender as $extender) {
- $extender->options_summary($categories, $options);
- }
- }
- /**
- * Provide the default form for setting options.
- */
- public function options_form(&$form, &$form_state) {
- parent::options_form($form, $form_state);
- if ($this->defaultable_sections($form_state['section'])) {
- views_ui_standard_display_dropdown($form, $form_state, $form_state['section']);
- }
- $form['#title'] = check_plain($this->display->display_title) . ': ';
- // Set the 'section' to highlight on the form. If it's the item we're
- // looking at is pulling from the default display, reflect that. Don't use
- // is_defaulted since we want it to show up even on the default display.
- if (!empty($this->options['defaults'][$form_state['section']])) {
- $form['#section'] = 'default-' . $form_state['section'];
- }
- else {
- $form['#section'] = $this->display->id . '-' . $form_state['section'];
- }
- switch ($form_state['section']) {
- case 'display_id':
- $form['#title'] .= t('The machine name of this display');
- $form['display_id'] = array(
- '#type' => 'textfield',
- '#description' => t('This is machine name of the display.'),
- '#default_value' => !empty($this->display->new_id) ? $this->display->new_id : $this->display->id,
- '#required' => TRUE,
- '#size' => 64,
- );
- break;
- case 'display_title':
- $form['#title'] .= t('The name and the description of this display');
- $form['display_title'] = array(
- '#title' => t('Name'),
- '#type' => 'textfield',
- '#description' => t('This name will appear only in the administrative interface for the View.'),
- '#default_value' => $this->display->display_title,
- );
- $form['display_description'] = array(
- '#title' => t('Description'),
- '#type' => 'textfield',
- '#description' => t('This description will appear only in the administrative interface for the View.'),
- '#default_value' => $this->get_option('display_description'),
- );
- break;
- case 'display_comment':
- $form['#title'] .= t("This display's comments");
- $form['display_comment'] = array(
- '#type' => 'textarea',
- '#description' => t('This value will be seen and used only within the Views UI and can be used to document this display. You can use this to provide notes for other or future maintainers of your site about how or why this display is configured.'),
- '#default_value' => $this->get_option('display_comment'),
- );
- break;
- case 'title':
- $form['#title'] .= t('The title of this view');
- $form['title'] = array(
- '#type' => 'textfield',
- '#description' => t('This title will be displayed with the view, wherever titles are normally displayed; i.e, as the page title, block title, etc. Use <none> to not assign a title; this can allow other modules to control the page title.'),
- '#default_value' => $this->get_option('title'),
- );
- break;
- case 'css_class':
- $form['#title'] .= t('CSS class');
- $form['css_class'] = array(
- '#type' => 'textfield',
- '#description' => t('The CSS class names will be added to the view. This enables you to use specific CSS code for each view. You may define multiples classes separated by spaces.'),
- '#default_value' => $this->get_option('css_class'),
- );
- break;
- case 'use_ajax':
- $form['#title'] .= t('Use AJAX when available to load this view');
- $form['description'] = array(
- '#markup' => '<div class="description form-item">' . t('If set, this view will use an AJAX mechanism for paging, table sorting and exposed filters. This means the entire page will not refresh. It is not recommended that you use this if this view is the main content of the page as it will prevent deep linking to specific pages, but it is very useful for side content.') . '</div>',
- );
- $form['use_ajax'] = array(
- '#type' => 'radios',
- '#options' => array(1 => t('Yes'), 0 => t('No')),
- '#default_value' => $this->get_option('use_ajax') ? 1 : 0,
- );
- break;
- case 'hide_attachment_summary':
- $form['#title'] .= t('Hide attachments when displaying a contextual filter summary');
- $form['hide_attachment_summary'] = array(
- '#type' => 'radios',
- '#options' => array(1 => t('Yes'), 0 => t('No')),
- '#default_value' => $this->get_option('hide_attachment_summary') ? 1 : 0,
- );
- break;
- case 'hide_admin_links':
- $form['#title'] .= t('Hide contextual links on this view.');
- $form['hide_admin_links'] = array(
- '#type' => 'radios',
- '#options' => array(1 => t('Yes'), 0 => t('No')),
- '#default_value' => $this->get_option('hide_admin_links') ? 1 : 0,
- );
- break;
- case 'use_more':
- $form['#title'] .= t('Add a more link to the bottom of the display.');
- $form['use_more'] = array(
- '#type' => 'checkbox',
- '#title' => t('Create more link'),
- '#description' => t("This will add a more link to the bottom of this view, which will link to the page view. If you have more than one page view, the link will point to the display specified in 'Link display' section under advanced. You can override the url at the link display setting."),
- '#default_value' => $this->get_option('use_more'),
- );
- $form['use_more_always'] = array(
- '#type' => 'checkbox',
- '#title' => t("Display 'more' link only if there is more content"),
- '#description' => t("Leave this unchecked to display the 'more' link even if there are no more items to display."),
- '#default_value' => !$this->get_option('use_more_always'),
- '#dependency' => array(
- 'edit-use-more' => array(TRUE),
- ),
- );
- $form['open_new_window'] = array(
- '#type' => 'checkbox',
- '#title' => t("Open 'more' link in new window (target='blank')"),
- '#description' => t("Leave this unchecked to open the more link in the same window."),
- '#default_value' => $this->get_option('open_new_window'),
- '#dependency' => array(
- 'edit-use-more' => array(TRUE),
- ),
- );
- $form['use_more_text'] = array(
- '#type' => 'textfield',
- '#title' => t('More link text'),
- '#description' => t("The text to display for the more link."),
- '#default_value' => $this->get_option('use_more_text'),
- '#dependency' => array(
- 'edit-use-more' => array(TRUE),
- ),
- );
- break;
- case 'group_by':
- $form['#title'] .= t('Allow grouping and aggregation (calculation) of fields.');
- $form['group_by'] = array(
- '#type' => 'checkbox',
- '#title' => t('Aggregate'),
- '#description' => t('If enabled, some fields may become unavailable. All fields that are selected for grouping will be collapsed to one record per distinct value. Other fields which are selected for aggregation will have the function run on them. For example, you can group nodes on title and count the number of nids in order to get a list of duplicate titles.'),
- '#default_value' => $this->get_option('group_by'),
- );
- break;
- case 'access':
- $form['#title'] .= t('Access restrictions');
- $form['access'] = array(
- '#prefix' => '<div class="clearfix">',
- '#suffix' => '</div>',
- '#tree' => TRUE,
- );
- $access = $this->get_option('access');
- $form['access']['type'] = array(
- '#type' => 'radios',
- '#options' => views_fetch_plugin_names('access', NULL, array($this->view->base_table)),
- '#default_value' => $access['type'],
- );
- $access_plugin = views_fetch_plugin_data('access', $access['type']);
- if (!empty($access_plugin['uses options'])) {
- $form['markup'] = array(
- '#prefix' => '<div class="form-item description">',
- '#markup' => t('You may also adjust the !settings for the currently selected access restriction.', array('!settings' => $this->option_link(t('settings'), 'access_options'))),
- '#suffix' => '</div>',
- );
- }
- break;
- case 'access_options':
- $access = $this->get_option('access');
- $plugin = $this->get_plugin('access');
- $form['#title'] .= t('Access options');
- if ($plugin) {
- if (!empty($plugin->definition['help topic'])) {
- $form['#help_topic'] = $plugin->definition['help topic'];
- }
- if (!empty($plugin->definition['module'])) {
- $form['#help_module'] = $plugin->definition['module'];
- }
- $form['access_options'] = array(
- '#tree' => TRUE,
- );
- $form['access_options']['type'] = array(
- '#type' => 'value',
- '#value' => $access['type'],
- );
- $plugin->options_form($form['access_options'], $form_state);
- }
- break;
- case 'cache':
- $form['#title'] .= t('Caching');
- $form['cache'] = array(
- '#prefix' => '<div class="clearfix">',
- '#suffix' => '</div>',
- '#tree' => TRUE,
- );
- $cache = $this->get_option('cache');
- $form['cache']['type'] = array(
- '#type' => 'radios',
- '#options' => views_fetch_plugin_names('cache', NULL, array($this->view->base_table)),
- '#default_value' => $cache['type'],
- );
- $cache_plugin = views_fetch_plugin_data('cache', $cache['type']);
- if (!empty($cache_plugin['uses options'])) {
- $form['markup'] = array(
- '#prefix' => '<div class="form-item description">',
- '#suffix' => '</div>',
- '#markup' => t('You may also adjust the !settings for the currently selected cache mechanism.', array('!settings' => $this->option_link(t('settings'), 'cache_options'))),
- );
- }
- break;
- case 'cache_options':
- $cache = $this->get_option('cache');
- $plugin = $this->get_plugin('cache');
- $form['#title'] .= t('Caching options');
- if ($plugin) {
- if (!empty($plugin->definition['help topic'])) {
- $form['#help_topic'] = $plugin->definition['help topic'];
- }
- if (!empty($plugin->definition['module'])) {
- $form['#help_module'] = $plugin->definition['module'];
- }
- $form['cache_options'] = array(
- '#tree' => TRUE,
- );
- $form['cache_options']['type'] = array(
- '#type' => 'value',
- '#value' => $cache['type'],
- );
- $plugin->options_form($form['cache_options'], $form_state);
- }
- break;
- case 'query':
- $query_options = $this->get_option('query');
- $plugin_name = $query_options['type'];
- $form['#title'] .= t('Query options');
- $this->view->init_query();
- if ($this->view->query) {
- if (!empty($this->view->query->definition['help topic'])) {
- $form['#help_topic'] = $this->view->query->definition['help topic'];
- }
- if (!empty($this->view->query->definition['module'])) {
- $form['#help_module'] = $this->view->query->definition['module'];
- }
- $form['query'] = array(
- '#tree' => TRUE,
- 'type' => array(
- '#type' => 'value',
- '#value' => $plugin_name,
- ),
- 'options' => array(
- '#tree' => TRUE,
- ),
- );
- $this->view->query->options_form($form['query']['options'], $form_state);
- }
- break;
- case 'field_language':
- $form['#title'] .= t('Field Language');
- $entities = entity_get_info();
- $entity_tables = array();
- $has_translation_handlers = FALSE;
- foreach ($entities as $type => $entity_info) {
- $entity_tables[] = $entity_info['base table'];
- if (!empty($entity_info['translation'])) {
- $has_translation_handlers = TRUE;
- }
- }
- // Doesn't make sense to show a field setting here if we aren't querying
- // an entity base table. Also, we make sure that there's at least one
- // entity type with a translation handler attached.
- if (in_array($this->view->base_table, $entity_tables) && $has_translation_handlers) {
- $languages = array(
- '***CURRENT_LANGUAGE***' => t("Current user's language"),
- '***DEFAULT_LANGUAGE***' => t("Default site language"),
- LANGUAGE_NONE => t('Language neutral'),
- );
- $languages = array_merge($languages, views_language_list());
- $form['field_language'] = array(
- '#type' => 'select',
- '#title' => t('Field Language'),
- '#description' => t('All fields which support translations will be displayed in the selected language.'),
- '#options' => $languages,
- '#default_value' => $this->get_option('field_language'),
- );
- $form['field_language_add_to_query'] = array(
- '#type' => 'checkbox',
- '#title' => t('When needed, add the field language condition to the query'),
- '#default_value' => $this->get_option('field_language_add_to_query'),
- );
- }
- else {
- $form['field_language']['#markup'] = t("You don't have translatable entity types.");
- }
- break;
- case 'style_plugin':
- $form['#title'] .= t('How should this view be styled');
- $form['#help_topic'] = 'style';
- $form['style_plugin'] = array(
- '#type' => 'radios',
- '#options' => views_fetch_plugin_names('style', $this->get_style_type(), array($this->view->base_table)),
- '#default_value' => $this->get_option('style_plugin'),
- '#description' => t('If the style you choose has settings, be sure to click the settings button that will appear next to it in the View summary.'),
- );
- $style_plugin = views_fetch_plugin_data('style', $this->get_option('style_plugin'));
- if (!empty($style_plugin['uses options'])) {
- $form['markup'] = array(
- '#markup' => '<div class="form-item description">' . t('You may also adjust the !settings for the currently selected style.', array('!settings' => $this->option_link(t('settings'), 'style_options'))) . '</div>',
- );
- }
- break;
- case 'style_options':
- $form['#title'] .= t('Style options');
- $style = TRUE;
- $type = 'style_plugin';
- $name = $this->get_option('style_plugin');
- case 'row_options':
- if (!isset($name)) {
- $name = $this->get_option('row_plugin');
- }
- // If row, $style will be empty.
- if (empty($style)) {
- $form['#title'] .= t('Row style options');
- $type = 'row_plugin';
- }
- $plugin = $this->get_plugin(empty($style) ? 'row' : 'style');
- if ($plugin) {
- if (!empty($plugin->definition['help topic'])) {
- $form['#help_topic'] = $plugin->definition['help topic'];
- }
- if (!empty($plugin->definition['module'])) {
- $form['#help_module'] = $plugin->definition['module'];
- }
- $form[$form_state['section']] = array(
- '#tree' => TRUE,
- );
- $plugin->options_form($form[$form_state['section']], $form_state);
- }
- break;
- case 'row_plugin':
- $form['#title'] .= t('How should each row in this view be styled');
- $form['#help_topic'] = 'style-row';
- $form['row_plugin'] = array(
- '#type' => 'radios',
- '#options' => views_fetch_plugin_names('row', $this->get_style_type(), array($this->view->base_table)),
- '#default_value' => $this->get_option('row_plugin'),
- );
- $row_plugin = views_fetch_plugin_data('row', $this->get_option('row_plugin'));
- if (!empty($row_plugin['uses options'])) {
- $form['markup'] = array(
- '#markup' => '<div class="form-item description">' . t('You may also adjust the !settings for the currently selected row style.', array('!settings' => $this->option_link(t('settings'), 'row_options'))) . '</div>',
- );
- }
- break;
- case 'link_display':
- $form['#title'] .= t('Which display to use for path');
- foreach ($this->view->display as $display_id => $display) {
- if ($display->handler->has_path()) {
- $options[$display_id] = $display->display_title;
- }
- }
- $options['custom_url'] = t('Custom URL');
- if (count($options)) {
- $form['link_display'] = array(
- '#type' => 'radios',
- '#options' => $options,
- '#description' => t("Which display to use to get this display's path for things like summary links, rss feed links, more links, etc."),
- '#default_value' => $this->get_option('link_display'),
- );
- }
- $options = array();
- // This lets us prepare the key as we want it printed.
- $count = 0;
- foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
- $options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name()));
- $options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name()));
- }
- // Default text. We have some options, so make a list.
- $output = '';
- if (!empty($options)) {
- $output = t('<p>The following tokens are available for this link.</p>');
- foreach (array_keys($options) as $type) {
- if (!empty($options[$type])) {
- $items = array();
- foreach ($options[$type] as $key => $value) {
- $items[] = $key . ' == ' . $value;
- }
- $output .= theme('item_list',
- array(
- 'items' => $items,
- 'type' => $type,
- ));
- }
- }
- }
- $form['link_url'] = array(
- '#type' => 'textfield',
- '#title' => t('Custom URL'),
- '#default_value' => $this->get_option('link_url'),
- '#description' => t('A Drupal path or external URL the more link will point to. Note that this will override the link display setting above.') . $output,
- '#dependency' => array('radio:link_display' => array('custom_url')),
- );
- break;
- case 'analyze-theme':
- $form['#title'] .= t('Theming information');
- $form['#help_topic'] = 'analyze-theme';
- if (isset($_POST['theme'])) {
- $this->theme = $_POST['theme'];
- }
- elseif (empty($this->theme)) {
- $this->theme = variable_get('theme_default', 'bartik');
- }
- if (isset($GLOBALS['theme']) && $GLOBALS['theme'] == $this->theme) {
- $this->theme_registry = theme_get_registry();
- $theme_engine = $GLOBALS['theme_engine'];
- }
- else {
- $themes = list_themes();
- $theme = $themes[$this->theme];
- // Find all our ancestor themes and put them in an array.
- $base_theme = array();
- $ancestor = $this->theme;
- while ($ancestor && isset($themes[$ancestor]->base_theme)) {
- $ancestor = $themes[$ancestor]->base_theme;
- $base_theme[] = $themes[$ancestor];
- }
- // The base themes should be initialized in the right order.
- $base_theme = array_reverse($base_theme);
- // This code is copied directly from _drupal_theme_initialize().
- $theme_engine = NULL;
- // Initialize the theme.
- if (isset($theme->engine)) {
- // Include the engine.
- include_once DRUPAL_ROOT . '/' . $theme->owner;
- $theme_engine = $theme->engine;
- if (function_exists($theme_engine . '_init')) {
- foreach ($base_theme as $base) {
- call_user_func($theme_engine . '_init', $base);
- }
- call_user_func($theme_engine . '_init', $theme);
- }
- }
- else {
- // Include non-engine theme files.
- foreach ($base_theme as $base) {
- // Include the theme file or the engine.
- if (!empty($base->owner)) {
- include_once DRUPAL_ROOT . '/' . $base->owner;
- }
- }
- // And our theme gets one too.
- if (!empty($theme->owner)) {
- include_once DRUPAL_ROOT . '/' . $theme->owner;
- }
- }
- $this->theme_registry = _theme_load_registry($theme, $base_theme, $theme_engine);
- }
- // If there's a theme engine involved, we also need to know its
- // extension so we can give the proper filename.
- $this->theme_extension = '.tpl.php';
- if (isset($theme_engine)) {
- $extension_function = $theme_engine . '_extension';
- if (function_exists($extension_function)) {
- $this->theme_extension = $extension_function();
- }
- }
- $funcs = array();
- // Get theme functions for the display. Note that some displays may not
- // have themes. The 'feed' display, for example, completely delegates to
- // the style.
- if (!empty($this->definition['theme'])) {
- $funcs[] = $this->option_link(t('Display output'), 'analyze-theme-display') . ': ' . $this->format_themes($this->theme_functions());
- $themes = $this->additional_theme_functions();
- if ($themes) {
- foreach ($themes as $theme) {
- $funcs[] = $this->option_link(t('Alternative display output'), 'analyze-theme-display') . ': ' . $this->format_themes($theme);
- }
- }
- }
- $plugin = $this->get_plugin();
- if ($plugin) {
- $funcs[] = $this->option_link(t('Style output'), 'analyze-theme-style') . ': ' . $this->format_themes($plugin->theme_functions(), $plugin->additional_theme_functions());
- $themes = $plugin->additional_theme_functions();
- if ($themes) {
- foreach ($themes as $theme) {
- $funcs[] = $this->option_link(t('Alternative style'), 'analyze-theme-style') . ': ' . $this->format_themes($theme);
- }
- }
- if ($plugin->uses_row_plugin()) {
- $row_plugin = $this->get_plugin('row');
- if ($row_plugin) {
- $funcs[] = $this->option_link(t('Row style output'), 'analyze-theme-row') . ': ' . $this->format_themes($row_plugin->theme_functions());
- $themes = $row_plugin->additional_theme_functions();
- if ($themes) {
- foreach ($themes as $theme) {
- $funcs[] = $this->option_link(t('Alternative row style'), 'analyze-theme-row') . ': ' . $this->format_themes($theme);
- }
- }
- }
- }
- if ($plugin->uses_fields()) {
- foreach ($this->get_handlers('field') as $id => $handler) {
- $funcs[] = $this->option_link(t('Field @field (ID: @id)', array('@field' => $handler->ui_name(), '@id' => $id)), 'analyze-theme-field') . ': ' . $this->format_themes($handler->theme_functions());
- }
- }
- }
- $form['important'] = array(
- '#markup' => '<div class="form-item description"><p>' . t('This section lists all possible templates for the display plugin and for the style plugins, ordered roughly from the least specific to the most specific. The active template for each plugin -- which is the most specific template found on the system -- is highlighted in bold.') . '</p></div>',
- );
- if (isset($this->view->display[$this->view->current_display]->new_id)) {
- $form['important']['new_id'] = array(
- '#prefix' => '<div class="description">',
- '#suffix' => '</div>',
- '#value' => t("<strong>Important!</strong> You have changed the display's machine name. Anything that attached to this display specifically, such as theming, may stop working until it is updated. To see theme suggestions for it, you need to save the view."),
- );
- }
- foreach (list_themes() as $key => $theme) {
- if (!empty($theme->info['hidden'])) {
- continue;
- }
- $options[$key] = $theme->info['name'];
- }
- $form['box'] = array(
- '#prefix' => '<div class="container-inline">',
- '#suffix' => '</div>',
- );
- $form['box']['theme'] = array(
- '#type' => 'select',
- '#options' => $options,
- '#default_value' => $this->theme,
- );
- $form['box']['change'] = array(
- '#type' => 'submit',
- '#value' => t('Change theme'),
- '#submit' => array('views_ui_edit_display_form_change_theme'),
- );
- $form['analysis'] = array(
- '#markup' => '<div class="form-item">' . theme('item_list', array('items' => $funcs)) . '</div>',
- );
- $form['rescan_button'] = array(
- '#prefix' => '<div class="form-item">',
- '#suffix' => '</div>',
- );
- $form['rescan_button']['button'] = array(
- '#type' => 'submit',
- '#value' => t('Rescan template files'),
- '#submit' => array('views_ui_config_item_form_rescan'),
- );
- $form['rescan_button']['markup'] = array(
- '#markup' => '<div class="description">' . t("<strong>Important!</strong> When adding, removing, or renaming template files, it is necessary to make Drupal aware of the changes by making it rescan the files on your system. By clicking this button you clear Drupal's theme registry and thereby trigger this rescanning process. The highlighted templates above will then reflect the new state of your system.") . '</div>',
- );
- $form_state['ok_button'] = TRUE;
- break;
- case 'analyze-theme-display':
- $form['#title'] .= t('Theming information (display)');
- $output = '<p>' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '</p>';
- if (empty($this->definition['theme'])) {
- $output .= t('This display has no theming information');
- }
- else {
- $output .= '<p>' . t('This is the default theme template used for this display.') . '</p>';
- $output .= '<pre>' . check_plain(file_get_contents('./' . $this->definition['theme path'] . '/' . strtr($this->definition['theme'], '_', '-') . '.tpl.php')) . '</pre>';
- }
- if (!empty($this->definition['additional themes'])) {
- foreach ($this->definition['additional themes'] as $theme => $type) {
- $output .= '<p>' . t('This is an alternative template for this display.') . '</p>';
- $output .= '<pre>' . check_plain(file_get_contents('./' . $this->definition['theme path'] . '/' . strtr($theme, '_', '-') . '.tpl.php')) . '</pre>';
- }
- }
- $form['analysis'] = array(
- '#markup' => '<div class="form-item">' . $output . '</div>',
- );
- $form_state['ok_button'] = TRUE;
- break;
- case 'analyze-theme-style':
- $form['#title'] .= t('Theming information (style)');
- $output = '<p>' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '</p>';
- $plugin = $this->get_plugin();
- if (empty($plugin->definition['theme'])) {
- $output .= t('This display has no style theming information');
- }
- else {
- $output .= '<p>' . t('This is the default theme template used for this style.') . '</p>';
- $output .= '<pre>' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . '.tpl.php')) . '</pre>';
- }
- if (!empty($plugin->definition['additional themes'])) {
- foreach ($plugin->definition['additional themes'] as $theme => $type) {
- $output .= '<p>' . t('This is an alternative template for this style.') . '</p>';
- $output .= '<pre>' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($theme, '_', '-') . '.tpl.php')) . '</pre>';
- }
- }
- $form['analysis'] = array(
- '#markup' => '<div class="form-item">' . $output . '</div>',
- );
- $form_state['ok_button'] = TRUE;
- break;
- case 'analyze-theme-row':
- $form['#title'] .= t('Theming information (row style)');
- $output = '<p>' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '</p>';
- $plugin = $this->get_plugin('row');
- if (empty($plugin->definition['theme'])) {
- $output .= t('This display has no row style theming information');
- }
- else {
- $output .= '<p>' . t('This is the default theme template used for this row style.') . '</p>';
- $output .= '<pre>' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . '.tpl.php')) . '</pre>';
- }
- if (!empty($plugin->definition['additional themes'])) {
- foreach ($plugin->definition['additional themes'] as $theme => $type) {
- $output .= '<p>' . t('This is an alternative template for this row style.') . '</p>';
- $output .= '<pre>' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($theme, '_', '-') . '.tpl.php')) . '</pre>';
- }
- }
- $form['analysis'] = array(
- '#markup' => '<div class="form-item">' . $output . '</div>',
- );
- $form_state['ok_button'] = TRUE;
- break;
- case 'analyze-theme-field':
- $form['#title'] .= t('Theming information (row style)');
- $output = '<p>' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '</p>';
- $output .= '<p>' . t('This is the default theme template used for this row style.') . '</p>';
- // Field templates aren't registered the normal way... and they're
- // always this one, anyhow.
- $output .= '<pre>' . check_plain(file_get_contents(drupal_get_path('module', 'views') . '/theme/views-view-field.tpl.php')) . '</pre>';
- $form['analysis'] = array(
- '#markup' => '<div class="form-item">' . $output . '</div>',
- );
- $form_state['ok_button'] = TRUE;
- break;
- case 'exposed_block':
- $form['#title'] .= t('Put the exposed form in a block');
- $form['description'] = array(
- '#markup' => '<div class="description form-item">' . t('If set, any exposed widgets will not appear with this view. Instead, a block will be made available to the Drupal block administration system, and the exposed form will appear there. Note that this block must be enabled manually, Views will not enable it for you.') . '</div>',
- );
- $form['exposed_block'] = array(
- '#type' => 'radios',
- '#options' => array(1 => t('Yes'), 0 => t('No')),
- '#default_value' => $this->get_option('exposed_block') ? 1 : 0,
- );
- break;
- case 'exposed_form':
- $form['#title'] .= t('Exposed Form');
- $form['exposed_form'] = array(
- '#prefix' => '<div class="clearfix">',
- '#suffix' => '</div>',
- '#tree' => TRUE,
- );
- $exposed_form = $this->get_option('exposed_form');
- $form['exposed_form']['type'] = array(
- '#type' => 'radios',
- '#options' => views_fetch_plugin_names('exposed_form', NULL, array($this->view->base_table)),
- '#default_value' => $exposed_form['type'],
- );
- $exposed_form_plugin = views_fetch_plugin_data('exposed_form', $exposed_form['type']);
- if (!empty($exposed_form_plugin['uses options'])) {
- $form['markup'] = array(
- '#prefix' => '<div class="form-item description">',
- '#suffix' => '</div>',
- '#markup' => t('You may also adjust the !settings for the currently selected style.', array('!settings' => $this->option_link(t('settings'), 'exposed_form_options'))),
- );
- }
- break;
- case 'exposed_form_options':
- $plugin = $this->get_plugin('exposed_form');
- $form['#title'] .= t('Exposed form options');
- if ($plugin) {
- if (!empty($plugin->definition['help topic'])) {
- $form['#help_topic'] = $plugin->definition['help topic'];
- }
- if (!empty($plugin->definition['module'])) {
- $form['#help_module'] = $plugin->definition['module'];
- }
- $form['exposed_form_options'] = array(
- '#tree' => TRUE,
- );
- $plugin->options_form($form['exposed_form_options'], $form_state);
- }
- break;
- case 'pager':
- $form['#title'] .= t('Select which pager, if any, to use for this view');
- $form['pager'] = array(
- '#prefix' => '<div class="clearfix">',
- '#suffix' => '</div>',
- '#tree' => TRUE,
- );
- $pager = $this->get_option('pager');
- $form['pager']['type'] = array(
- '#type' => 'radios',
- '#options' => views_fetch_plugin_names('pager', empty($this->definition['use pager']) ? 'basic' : NULL, array($this->view->base_table)),
- '#default_value' => $pager['type'],
- );
- $pager_plugin = views_fetch_plugin_data('pager', $pager['type']);
- if (!empty($pager_plugin['uses options'])) {
- $form['markup'] = array(
- '#prefix' => '<div class="form-item description">',
- '#suffix' => '</div>',
- '#markup' => t('You may also adjust the !settings for the currently selected pager.', array('!settings' => $this->option_link(t('settings'), 'pager_options'))),
- );
- }
- break;
- case 'pager_options':
- $plugin = $this->get_plugin('pager');
- $form['#title'] .= t('Pager options');
- if ($plugin) {
- if (!empty($plugin->definition['help topic'])) {
- $form['#help_topic'] = $plugin->definition['help topic'];
- }
- if (!empty($plugin->definition['module'])) {
- $form['#help_module'] = $plugin->definition['module'];
- }
- $form['pager_options'] = array(
- '#tree' => TRUE,
- );
- $plugin->options_form($form['pager_options'], $form_state);
- }
- break;
- }
- foreach ($this->extender as $extender) {
- $extender->options_form($form, $form_state);
- }
- }
- /**
- * Format a list of theme templates for output by the theme info helper.
- */
- public function format_themes($themes) {
- $registry = $this->theme_registry;
- $extension = $this->theme_extension;
- $output = '';
- $picked = FALSE;
- foreach ($themes as $theme) {
- $template = strtr($theme, '_', '-') . $extension;
- if (!$picked && !empty($registry[$theme])) {
- $template_path = isset($registry[$theme]['path']) ? $registry[$theme]['path'] . '/' : './';
- if (file_exists($template_path . $template)) {
- $hint = t('File found in folder @template-path', array('@template-path' => $template_path));
- $template = '<strong title="' . $hint . '">' . $template . '</strong>';
- }
- else {
- $template = '<strong class="error">' . $template . ' ' . t('(File not found, in folder @template-path)', array('@template-path' => $template_path)) . '</strong>';
- }
- $picked = TRUE;
- }
- $fixed[] = $template;
- }
- return theme('item_list', array('items' => array_reverse($fixed)));
- }
- /**
- * Validate the options form.
- */
- public function options_validate(&$form, &$form_state) {
- switch ($form_state['section']) {
- case 'display_title':
- if (empty($form_state['values']['display_title'])) {
- form_error($form['display_title'], t('Display title may not be empty.'));
- }
- break;
- case 'css_class':
- $css_class = $form_state['values']['css_class'];
- if (preg_match('/[^a-zA-Z0-9-_ ]/', $css_class)) {
- form_error($form['css_class'], t('CSS classes must be alphanumeric or dashes only.'));
- }
- break;
- case 'display_id':
- if ($form_state['values']['display_id']) {
- if (preg_match('/[^a-z0-9_]/', $form_state['values']['display_id'])) {
- form_error($form['display_id'], t('Display name must be letters, numbers, or underscores only.'));
- }
- foreach ($this->view->display as $id => $display) {
- if ($id != $this->view->current_display && ($form_state['values']['display_id'] == $id || (isset($display->new_id) && $form_state['values']['display_id'] == $display->new_id))) {
- form_error($form['display_id'], t('Display id should be unique.'));
- }
- }
- }
- break;
- case 'style_options':
- $style = TRUE;
- case 'row_options':
- // If row, $style will be empty.
- $plugin = $this->get_plugin(empty($style) ? 'row' : 'style');
- if ($plugin) {
- $plugin->options_validate($form[$form_state['section']], $form_state);
- }
- break;
- case 'access_options':
- $plugin = $this->get_plugin('access');
- if ($plugin) {
- $plugin->options_validate($form['access_options'], $form_state);
- }
- break;
- case 'query':
- if ($this->view->query) {
- $this->view->query->options_validate($form['query'], $form_state);
- }
- break;
- case 'cache_options':
- $plugin = $this->get_plugin('cache');
- if ($plugin) {
- $plugin->options_validate($form['cache_options'], $form_state);
- }
- break;
- case 'exposed_form_options':
- $plugin = $this->get_plugin('exposed_form');
- if ($plugin) {
- $plugin->options_validate($form['exposed_form_options'], $form_state);
- }
- break;
- case 'pager_options':
- $plugin = $this->get_plugin('pager');
- if ($plugin) {
- $plugin->options_validate($form['pager_options'], $form_state);
- }
- break;
- }
- foreach ($this->extender as $extender) {
- $extender->options_validate($form, $form_state);
- }
- }
- /**
- * Perform any necessary changes to the form values prior to storage.
- *
- * There is no need for this function to actually store the data.
- */
- public function options_submit(&$form, &$form_state) {
- // Not sure I like this being here, but it seems (?) like a logical place.
- $cache_plugin = $this->get_plugin('cache');
- if ($cache_plugin) {
- $cache_plugin->cache_flush();
- }
- $section = $form_state['section'];
- switch ($section) {
- case 'display_id':
- if (isset($form_state['values']['display_id'])) {
- $this->display->new_id = $form_state['values']['display_id'];
- }
- break;
- case 'display_title':
- $this->display->display_title = $form_state['values']['display_title'];
- $this->set_option('display_description', $form_state['values']['display_description']);
- break;
- case 'access':
- $access = $this->get_option('access');
- if ($access['type'] != $form_state['values']['access']['type']) {
- $plugin = views_get_plugin('access', $form_state['values']['access']['type']);
- if ($plugin) {
- $access = array('type' => $form_state['values']['access']['type']);
- $this->set_option('access', $access);
- if (!empty($plugin->definition['uses options'])) {
- views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('access_options'));
- }
- }
- }
- break;
- case 'access_options':
- $plugin = views_get_plugin('access', $form_state['values'][$section]['type']);
- if ($plugin) {
- $plugin->options_submit($form['access_options'], $form_state);
- $this->set_option('access', $form_state['values'][$section]);
- }
- break;
- case 'cache':
- $cache = $this->get_option('cache');
- if ($cache['type'] != $form_state['values']['cache']['type']) {
- $plugin = views_get_plugin('cache', $form_state['values']['cache']['type']);
- if ($plugin) {
- $cache = array('type' => $form_state['values']['cache']['type']);
- $this->set_option('cache', $cache);
- if (!empty($plugin->definition['uses options'])) {
- views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('cache_options'));
- }
- }
- }
- break;
- case 'cache_options':
- $plugin = views_get_plugin('cache', $form_state['values'][$section]['type']);
- if ($plugin) {
- $plugin->options_submit($form['cache_options'], $form_state);
- $this->set_option('cache', $form_state['values'][$section]);
- }
- break;
- case 'query':
- $plugin = $this->get_plugin('query');
- if ($plugin) {
- $plugin->options_submit($form['query']['options'], $form_state);
- $this->set_option('query', $form_state['values'][$section]);
- }
- break;
- case 'link_display':
- $this->set_option('link_url', $form_state['values']['link_url']);
- case 'title':
- case 'css_class':
- case 'display_comment':
- $this->set_option($section, $form_state['values'][$section]);
- break;
- case 'field_language':
- $this->set_option('field_language', $form_state['values']['field_language']);
- $this->set_option('field_language_add_to_query', $form_state['values']['field_language_add_to_query']);
- break;
- case 'use_ajax':
- case 'hide_attachment_summary':
- case 'hide_admin_links':
- $this->set_option($section, (bool) $form_state['values'][$section]);
- break;
- case 'use_more':
- $this->set_option($section, intval($form_state['values'][$section]));
- $this->set_option('use_more_always', !intval($form_state['values']['use_more_always']));
- $this->set_option('open_new_window', $form_state['values']['open_new_window']) == '1';
- $this->set_option('use_more_text', $form_state['values']['use_more_text']);
- case 'distinct':
- $this->set_option($section, $form_state['values'][$section]);
- break;
- case 'group_by':
- $this->set_option($section, $form_state['values'][$section]);
- break;
- case 'row_plugin':
- // This if prevents resetting options to default if they don't change
- // the plugin.
- if ($this->get_option($section) != $form_state['values'][$section]) {
- $plugin = views_get_plugin('row', $form_state['values'][$section]);
- if ($plugin) {
- $this->set_option($section, $form_state['values'][$section]);
- $this->set_option('row_options', array());
- // Send ajax form to options page if we use it.
- if (!empty($plugin->definition['uses options'])) {
- views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('row_options'));
- }
- }
- }
- break;
- case 'style_plugin':
- // This if prevents resetting options to default if they don't change
- // the plugin.
- if ($this->get_option($section) != $form_state['values'][$section]) {
- $plugin = views_get_plugin('style', $form_state['values'][$section]);
- if ($plugin) {
- $this->set_option($section, $form_state['values'][$section]);
- $this->set_option('style_options', array());
- // Send ajax form to options page if we use it.
- if (!empty($plugin->definition['uses options'])) {
- views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('style_options'));
- }
- }
- }
- break;
- case 'style_options':
- $style = TRUE;
- case 'row_options':
- // If row, $style will be empty.
- $plugin = $this->get_plugin(empty($style) ? 'row' : 'style');
- if ($plugin) {
- $plugin->options_submit($form['options'][$section], $form_state);
- }
- $this->set_option($section, $form_state['values'][$section]);
- break;
- case 'exposed_block':
- $this->set_option($section, (bool) $form_state['values'][$section]);
- break;
- case 'exposed_form':
- $exposed_form = $this->get_option('exposed_form');
- if ($exposed_form['type'] != $form_state['values']['exposed_form']['type']) {
- $plugin = views_get_plugin('exposed_form', $form_state['values']['exposed_form']['type']);
- if ($plugin) {
- $exposed_form = array('type' => $form_state['values']['exposed_form']['type'], 'options' => array());
- $this->set_option('exposed_form', $exposed_form);
- if (!empty($plugin->definition['uses options'])) {
- views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('exposed_form_options'));
- }
- }
- }
- break;
- case 'exposed_form_options':
- $plugin = $this->get_plugin('exposed_form');
- if ($plugin) {
- $exposed_form = $this->get_option('exposed_form');
- $plugin->options_submit($form['exposed_form_options'], $form_state);
- $exposed_form['options'] = $form_state['values'][$section];
- $this->set_option('exposed_form', $exposed_form);
- }
- break;
- case 'pager':
- $pager = $this->get_option('pager');
- if ($pager['type'] != $form_state['values']['pager']['type']) {
- $plugin = views_get_plugin('pager', $form_state['values']['pager']['type']);
- if ($plugin) {
- // Because pagers have very similar options, let's allow pagers to
- // try to carry the options over.
- $plugin->init($this->view, $this->display, $pager['options']);
- $pager = array('type' => $form_state['values']['pager']['type'], 'options' => $plugin->options);
- $this->set_option('pager', $pager);
- if (!empty($plugin->definition['uses options'])) {
- views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('pager_options'));
- }
- }
- }
- break;
- case 'pager_options':
- $plugin = $this->get_plugin('pager');
- if ($plugin) {
- $pager = $this->get_option('pager');
- $plugin->options_submit($form['pager_options'], $form_state);
- $pager['options'] = $form_state['values'][$section];
- $this->set_option('pager', $pager);
- }
- break;
- }
- foreach ($this->extender as $extender) {
- $extender->options_submit($form, $form_state);
- }
- }
- /**
- * If override/revert was clicked, perform the proper toggle.
- */
- public function options_override($form, &$form_state) {
- $this->set_override($form_state['section']);
- }
- /**
- * Flip the override setting for the given section.
- *
- * @param string $section
- * Which option should be marked as overridden, for example "filters".
- * @param bool $new_state
- * Select the new state of the option.
- * - TRUE: Revert to default.
- * - FALSE: Mark it as overridden.
- */
- public function set_override($section, $new_state = NULL) {
- $options = $this->defaultable_sections($section);
- if (!$options) {
- return;
- }
- if (!isset($new_state)) {
- $new_state = empty($this->options['defaults'][$section]);
- }
- // For each option that is part of this group, fix our settings.
- foreach ($options as $option) {
- if ($new_state) {
- // Revert to defaults.
- unset($this->options[$option]);
- unset($this->display->display_options[$option]);
- }
- else {
- // Copy existing values into our display.
- $this->options[$option] = $this->get_option($option);
- $this->display->display_options[$option] = $this->options[$option];
- }
- $this->options['defaults'][$option] = $new_state;
- $this->display->display_options['defaults'][$option] = $new_state;
- }
- }
- /**
- * Inject anything into the query that the display handler needs.
- */
- public function query() {
- foreach ($this->extender as $extender) {
- $extender->query();
- }
- }
- /**
- * Not all display plugins will support filtering.
- */
- public function render_filters() {
- }
- /**
- * Not all display plugins will suppert pager rendering.
- */
- public function render_pager() {
- return TRUE;
- }
- /**
- * Render the 'more' link.
- */
- public function render_more_link() {
- if ($this->use_more() && ($this->use_more_always() || (!empty($this->view->query->pager) && $this->view->query->pager->has_more_records()))) {
- $path = $this->get_path();
- if ($this->get_option('link_display') == 'custom_url' && $override_path = $this->get_option('link_url')) {
- $tokens = $this->get_arguments_tokens();
- $path = strtr($override_path, $tokens);
- }
- if ($path) {
- if (empty($override_path)) {
- $path = $this->view->get_url(NULL, $path);
- }
- $url_options = array();
- if (!empty($this->view->exposed_raw_input)) {
- $url_options['query'] = $this->view->exposed_raw_input;
- }
- $theme = views_theme_functions('views_more', $this->view, $this->display);
- $parsed_url = drupal_parse_url($path);
- // Preserve the query string from url.
- if (!empty($parsed_url['query'])) {
- if (!empty($url_options['query'])) {
- $url_options['query'] = array_merge($parsed_url['query'], $url_options['query']);
- }
- else {
- $url_options['query'] = $parsed_url['query'];
- }
- $path = $parsed_url['path'];
- }
- // Add fragment if applicable.
- if (!empty($parsed_url['fragment'])) {
- $url_options['fragment'] = $parsed_url['fragment'];
- }
- $path = check_url(url($path, $url_options));
- return theme($theme, array(
- 'more_url' => $path,
- 'new_window' => $this->use_more_open_new_window(),
- 'link_text' => check_plain($this->use_more_text()),
- 'view' => $this->view,
- ));
- }
- }
- }
- /**
- * Legacy functions.
- */
- /**
- * Render the header of the view.
- */
- public function render_header() {
- $empty = !empty($this->view->result);
- return $this->render_area('header', $empty);
- }
- /**
- * Render the footer of the view.
- */
- public function render_footer() {
- $empty = !empty($this->view->result);
- return $this->render_area('footer', $empty);
- }
- /**
- *
- */
- public function render_empty() {
- return $this->render_area('empty');
- }
- /**
- * If this display creates a block, implement one of these.
- */
- public function hook_block_list($delta = 0, $edit = array()) {
- return array();
- }
- /**
- * If this display creates a page with a menu item, implement it here.
- */
- public function hook_menu() {
- return array();
- }
- /**
- * Render this display.
- */
- public function render() {
- return theme($this->theme_functions(), array('view' => $this->view));
- }
- /**
- *
- */
- public function render_area($area, $empty = FALSE) {
- $return = '';
- foreach ($this->get_handlers($area) as $area) {
- $return .= $area->render($empty);
- }
- return $return;
- }
- /**
- * Determine if the user has access to this display of the view.
- */
- public function access($account = NULL) {
- if (!isset($account)) {
- global $user;
- $account = $user;
- }
- // Full override.
- if (user_access('access all views', $account)) {
- return TRUE;
- }
- $plugin = $this->get_plugin('access');
- if ($plugin) {
- return $plugin->access($account);
- }
- // Fallback to all access if no plugin.
- return TRUE;
- }
- /**
- * Set up any variables on the view prior to execution.
- *
- * These are separated from execute because they are extremely common and
- * unlikely to be overridden on an individual display.
- */
- public function pre_execute() {
- $this->view->set_use_ajax($this->use_ajax());
- if ($this->use_more() && !$this->use_more_always()) {
- $this->view->get_total_rows = TRUE;
- }
- $this->view->init_handlers();
- if ($this->uses_exposed()) {
- $exposed_form = $this->get_plugin('exposed_form');
- $exposed_form->pre_execute();
- }
- foreach ($this->extender as $extender) {
- $extender->pre_execute();
- }
- if ($this->get_option('hide_admin_links')) {
- $this->view->hide_admin_links = TRUE;
- }
- }
- /**
- * When used externally, this is how a view gets run and returns
- * data in the format required.
- *
- * The base class cannot be executed.
- */
- public function execute() {
- }
- /**
- * Fully render the display.
- *
- * Used for the purposes of a live preview or some other AJAXy reason.
- */
- public function preview() {
- return $this->view->render();
- }
- /**
- * Displays can require a certain type of style plugin.
- *
- * By default, they will be 'normal'.
- */
- public function get_style_type() {
- return 'normal';
- }
- /**
- * Make sure the display and all associated handlers are valid.
- *
- * @return
- * Empty array if the display is valid; an array of error strings if it is
- * not.
- */
- public function validate() {
- $errors = array();
- // Make sure displays that use fields HAVE fields.
- if ($this->uses_fields()) {
- $fields = FALSE;
- foreach ($this->get_handlers('field') as $field) {
- if (empty($field->options['exclude'])) {
- $fields = TRUE;
- }
- }
- if (!$fields) {
- $errors[] = t('Display "@display" uses fields but there are none defined for it or all are excluded.', array('@display' => $this->display->display_title));
- }
- }
- if ($this->has_path() && !$this->get_option('path')) {
- $errors[] = t('Display "@display" uses a path but the path is undefined.', array('@display' => $this->display->display_title));
- }
- // Validate style plugin.
- $style = $this->get_plugin();
- if (empty($style)) {
- $errors[] = t('Display "@display" has an invalid style plugin.', array('@display' => $this->display->display_title));
- }
- else {
- $result = $style->validate();
- if (!empty($result) && is_array($result)) {
- $errors = array_merge($errors, $result);
- }
- }
- // Validate query plugin.
- $query = $this->get_plugin('query');
- $result = $query->validate();
- if (!empty($result) && is_array($result)) {
- $errors = array_merge($errors, $result);
- }
- // Validate handlers.
- foreach (views_object_types() as $type => $info) {
- foreach ($this->get_handlers($type) as $handler) {
- $result = $handler->validate();
- if (!empty($result) && is_array($result)) {
- $errors = array_merge($errors, $result);
- }
- }
- }
- return $errors;
- }
- /**
- * Check if the provided identifier is unique.
- *
- * @param string $id
- * The id of the handler which is checked.
- * @param string $identifier
- * The actual get identifier configured in the exposed settings.
- *
- * @return bool
- * Returns whether the identifier is unique on all handlers.
- */
- public function is_identifier_unique($id, $identifier) {
- foreach (views_object_types() as $type => $info) {
- foreach ($this->get_handlers($type) as $key => $handler) {
- if ($handler->can_expose() && $handler->is_exposed()) {
- if ($handler->is_a_group()) {
- if ($id != $key && $identifier == $handler->options['group_info']['identifier']) {
- return FALSE;
- }
- }
- else {
- if ($id != $key && isset($handler->options['expose']['identifier']) && $identifier == $handler->options['expose']['identifier']) {
- return FALSE;
- }
- }
- }
- }
- }
- return TRUE;
- }
- /**
- * Provide the block system with any exposed widget blocks for this display.
- */
- public function get_special_blocks() {
- $blocks = array();
- if ($this->uses_exposed_form_in_block()) {
- $delta = '-exp-' . $this->view->name . '-' . $this->display->id;
- $desc = t('Exposed form: @view-@display_id', array('@view' => $this->view->name, '@display_id' => $this->display->id));
- $blocks[$delta] = array(
- 'info' => $desc,
- 'cache' => DRUPAL_NO_CACHE,
- );
- }
- return $blocks;
- }
- /**
- * Render any special blocks provided for this display.
- */
- public function view_special_blocks($type) {
- if ($type == '-exp') {
- // Avoid interfering with the admin forms.
- if (arg(0) == 'admin' && arg(1) == 'structure' && arg(2) == 'views') {
- return;
- }
- $this->view->init_handlers();
- if ($this->uses_exposed() && $this->get_option('exposed_block')) {
- $exposed_form = $this->get_plugin('exposed_form');
- return array(
- 'content' => $exposed_form->render_exposed_form(TRUE),
- );
- }
- }
- }
- /**
- * Override of export_option()
- *
- * Because displays do not want to export options that are NOT overridden from
- * the default display, we need some special handling during the export
- * process.
- */
- public function export_option($indent, $prefix, $storage, $option, $definition, $parents) {
- // The $prefix is wrong because we store our actual options a little
- // differently.
- $prefix = '$handler->display->display_options';
- $output = '';
- if (!$parents && !$this->is_default_display()) {
- // Do not export items that are not overridden.
- if ($this->is_defaulted($option)) {
- return;
- }
- // If this is not defaulted and is overrideable, flip the switch to say
- // this is overridden.
- if ($this->defaultable_sections($option)) {
- $output .= $indent . $prefix . "['defaults']['$option'] = FALSE;\n";
- }
- }
- $output .= parent::export_option($indent, $prefix, $storage, $option, $definition, $parents);
- return $output;
- }
- /**
- * Special method to export items that have handlers.
- *
- * This method was specified in the option_definition() as the method to
- * utilize to export fields, filters, sort criteria, relationships and
- * arguments. This passes the export off to the individual handlers so that
- * they can export themselves properly.
- */
- public function export_handler($indent, $prefix, $storage, $option, $definition, $parents) {
- $output = '';
- // Cut the 's' off because the data is stored as the plural form but we need
- // the singular form.
- if ($option != 'header' && $option != 'footer' && $option != 'empty') {
- $type = substr($option, 0, -1);
- }
- else {
- $type = $option;
- }
- $types = views_object_types();
- foreach ($storage[$option] as $id => $info) {
- if (!empty($types[$type]['type'])) {
- $handler_type = $types[$type]['type'];
- }
- else {
- $handler_type = $type;
- }
- // If aggregation is on, the group type might override the actual handler
- // that is in use. This piece of code checks that and, if necessary, sets
- // the override handler.
- $override = NULL;
- if ($this->use_group_by() && !empty($info['group_type'])) {
- if (empty($this->view->query)) {
- $this->view->init_query();
- }
- $aggregate = $this->view->query->get_aggregation_info();
- if (!empty($aggregate[$info['group_type']]['handler'][$type])) {
- $override = $aggregate[$info['group_type']]['handler'][$type];
- }
- }
- $handler = views_get_handler($info['table'], $info['field'], $handler_type, $override);
- if ($handler) {
- $handler->init($this->view, $info);
- $output .= $indent . '/* ' . $types[$type]['stitle'] . ': ' . $handler->ui_name() . " */\n";
- $output .= $handler->export_options($indent, $prefix . "['$option']['$id']");
- }
- // Prevent reference problems.
- unset($handler);
- }
- return $output;
- }
- /**
- * Special handling for the style export.
- *
- * Styles are stored as style_plugin and style_options or row_plugin and
- * row_options accordingly. The options are told not to export, and the export
- * for the plugin should export both.
- */
- public function export_style($indent, $prefix, $storage, $option, $definition, $parents) {
- $output = '';
- $style_plugin = $this->get_plugin();
- if ($option == 'style_plugin') {
- $type = 'style';
- $options_field = 'style_options';
- $plugin = $style_plugin;
- }
- else {
- if (!$style_plugin || !$style_plugin->uses_row_plugin()) {
- return;
- }
- $type = 'row';
- $options_field = 'row_options';
- $plugin = $this->get_plugin('row');
- // If the style plugin doesn't use row plugins, don't even bother.
- }
- if ($plugin) {
- // Write which plugin to use.
- $value = $this->get_option($option);
- $output .= $indent . $prefix . "['$option'] = '$value';\n";
- // Pass off to the plugin to export itself.
- $output .= $plugin->export_options($indent, $prefix . "['$options_field']");
- }
- return $output;
- }
- /**
- * Special handling for plugin export.
- *
- * Plugins other than styles are stored in array with 'type' being the key
- * to the plugin. For modern plugins, the options are stored in the 'options'
- * array, but for legacy plugins (access and cache) options are stored as
- * siblings to the type.
- */
- public function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
- $output = '';
- $plugin_type = end($parents);
- $plugin = $this->get_plugin($plugin_type);
- if ($plugin) {
- // Write which plugin to use.
- $value = $storage[$option];
- $new_prefix = $prefix . "['$plugin_type']";
- $output .= $indent . $new_prefix . "['$option'] = '$value';\n";
- if ($plugin_type != 'access' && $plugin_type != 'cache') {
- $new_prefix .= "['options']";
- }
- // Pass off to the plugin to export itself.
- $output .= $plugin->export_options($indent, $new_prefix);
- }
- return $output;
- }
- /**
- *
- */
- public function unpack_style($indent, $prefix, $storage, $option, $definition, $parents) {
- $output = '';
- $style_plugin = $this->get_plugin();
- if ($option == 'style_plugin') {
- $type = 'style';
- $options_field = 'style_options';
- $plugin = $style_plugin;
- }
- else {
- if (!$style_plugin || !$style_plugin->uses_row_plugin()) {
- return;
- }
- $type = 'row';
- $options_field = 'row_options';
- $plugin = $this->get_plugin('row');
- // If the style plugin doesn't use row plugins, don't even bother.
- }
- if ($plugin) {
- return $plugin->unpack_translatables($translatable, $parents);
- }
- }
- /**
- * Special handling for plugin unpacking.
- */
- public function unpack_plugin(&$translatable, $storage, $option, $definition, $parents) {
- $plugin_type = end($parents);
- $plugin = $this->get_plugin($plugin_type);
- if ($plugin) {
- // Write which plugin to use.
- return $plugin->unpack_translatables($translatable, $parents);
- }
- }
- /**
- * Special method to unpack items that have handlers.
- *
- * This method was specified in the option_definition() as the method to
- * utilize to export fields, filters, sort criteria, relationships and
- * arguments. This passes the export off to the individual handlers so that
- * they can export themselves properly.
- */
- public function unpack_handler(&$translatable, $storage, $option, $definition, $parents) {
- $output = '';
- // Cut the 's' off because the data is stored as the plural form but we need
- // the singular form.
- if ($option != 'header' && $option != 'footer' && $option != 'empty') {
- $type = substr($option, 0, -1);
- }
- else {
- $type = $option;
- }
- $types = views_object_types();
- foreach ($storage[$option] as $id => $info) {
- if (!empty($types[$type]['type'])) {
- $handler_type = $types[$type]['type'];
- }
- else {
- $handler_type = $type;
- }
- $handler = views_get_handler($info['table'], $info['field'], $handler_type);
- if ($handler) {
- $handler->init($this->view, $info);
- $items = array_merge($parents, array($type, $info['table'], $info['id']));
- $handler->unpack_translatables($translatable, $items);
- }
- // Prevent reference problems.
- unset($handler);
- }
- return $output;
- }
- /**
- * Provide some helpful text for the arguments.
- *
- * The result should contain of an array with:
- * - filter value present: The title of the fieldset in the argument where
- * you can configure what should be done with a given argument.
- * - filter value not present: The tiel of the fieldset in the argument where
- * you can configure what should be done if the argument does not exist.
- * - description: A description about how arguments comes to the display. For
- * example blocks don't get it from url.
- */
- public function get_argument_text() {
- return array(
- 'filter value not present' => t('When the filter value is <em>NOT</em> available'),
- 'filter value present' => t('When the filter value <em>IS</em> available or a default is provided'),
- 'description' => t("This display does not have a source for contextual filters, so no contextual filter value will be available unless you select 'Provide default'."),
- );
- }
- /**
- * Provide some helpful text for pagers.
- *
- * The result should contain of an array with:
- * - items per page title.
- * - items per page description.
- */
- public function get_pager_text() {
- return array(
- 'items per page title' => t('Items to display'),
- 'items per page description' => t('The number of items to display. Enter 0 for no limit.'),
- );
- }
- }
- /**
- * @}
- */
|