/**
  * This function allows a user to insert an Action button to the page.
  * It accepts an `XMLElement` (which should be of the `Anchor` type),
  * an optional parameter `$prepend`, which when `true` will add this
  * action before any existing actions.
  *
  * @since Symphony 2.3
  * @see core.Widget#Anchor
  * @param XMLElement $action
  *  An Anchor element to add to the top of the page.
  * @param boolean $append
  *  If true, this will add the `$action` after existing actions, otherwise
  *  it will be added before existing actions. By default this is `true`,
  *  which will add the `$action` after current actions.
  */
 public function insertAction(XMLElement $action, $append = true)
 {
     $actions = $this->Context->getChildrenByName('ul');
     // Actions haven't be added yet, create the element
     if (empty($actions)) {
         $ul = new XMLElement('ul', NULL, array('class' => 'actions'));
         $this->Context->appendChild($ul);
     } else {
         $ul = current($actions);
         $this->Context->replaceChildAt(1, $ul);
     }
     $li = new XMLElement('li', $action);
     if ($append) {
         $ul->prependChild($li);
     } else {
         $ul->appendChild($li);
     }
 }
Пример #2
0
 private function findEntries(XMLElement $xml)
 {
     // check if xml has child elements
     if (($elements = $xml->getChildren()) && is_array($elements)) {
         // handle elements
         foreach ($elements as $element_index => $element) {
             // check if element is xml element
             if ($element instanceof XMLElement) {
                 // check if element is entry
                 if ($element->getName() === 'entry') {
                     // process fields
                     $element = $this->processFields($element);
                 } else {
                     // find entries
                     $element = $this->findEntries($element);
                 }
                 // replace element
                 $xml->replaceChildAt($element_index, $element);
             }
         }
     }
     return $xml;
 }