We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39941
    • 5 Posts
    I'm running Revo 2.2.4 and MyComponent 1.0.0 beta1.

    When I set the contentType of a resource to 'text/css' it is still shown as text/html after install. (Done in transport.resources.php - everything else worked.)
    [...]
    $resources[2]->fromArray(array(
        'id' => 2,
        'class_key' => 'modResource',
        'context_key' => 'web',
        'type' => 'document',
        'contentType' => 'text/css',
        'pagetitle' => 'style',
    [...]
    

    I tried to use the string '4' and integer 4 instead too.
    I also tried
    $resourceObject->set('contentType', 'text/css');
    after successfully getting the object in the resolver (which does work apart from that).
    In build.transport.php when setting the attributes for the vehicle for the resources I wondered if 'ContentType' (with uppercase C) might be the reason. I don't really understand if the RELATED_OBJECTS settings might be the problem.
    [...]
     $attributes= array(
        xPDOTransport::PRESERVE_KEYS => false,
        xPDOTransport::UPDATE_OBJECT => true,
        xPDOTransport::UNIQUE_KEY => 'pagetitle',
        xPDOTransport::RELATED_OBJECTS => true,
        xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array (
            'ContentType' => array(
                xPDOTransport::PRESERVE_KEYS => false,
                xPDOTransport::UPDATE_OBJECT => true,
                xPDOTransport::UNIQUE_KEY => 'name',
            ),
        ),
    [...]
    

    Commenting out the whole RELATED_OBJECT_ATTRIBUTES array didn't help.
    I am puzzled.
    When I checked after various installs with [ [*content_type]] and sometimes got a number (but only the '1') and once a string "text/html" I was lost.

    This question has been answered by webknot. See the first response.

      • 3749
      • 24,544 Posts
      Try this:


      'contentType' => 'css',


      I think MODX will convert it to 'text/css' for you.


      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
      • discuss.answer
        • 39941
        • 5 Posts
        Thank you again for helping me!
        No change.
        Tried in transport.resources.php and in the resolver.
        In table modx_site_content I can see, what I set (exactly as i did).
        No funny whitespace or so. The default page has a class key of 'modDocument' instead of 'modResource' but that seems harmless.
        When I the change the type in the backend afterwards, it looked the same as when I did it when installing, but worked...
        No... That's it!
        The difference was the content_type column in modx_site_content was not set according to the contentType column when installing from package.
        Setting it also was the solution/workaround:
        $resources[2] = $modx->newObject('modResource');
        $resources[2]->fromArray(array(
            'id' => 2,
            'class_key' => 'modResource',
            'context_key' => 'web',
            'type' => 'document',
            'contentType' => 'text/css',
            'content_type' => '4',
            'pagetitle' => 'style',
          • 3749
          • 24,544 Posts
          modDocument is correct if it's not a weblink, symlink, or static resource. modResource is the parent class and shouldn't actually appear in the class_key field (and can cause problems if it does).

          newObject('modResource') is fine, and I think MODX converts your setting for class_key to modDocument by default. You can save it the trouble by using 'class_key' => 'modDocument'.


          BTW, if it's a CSS file you're storing as a resource, you may actually want it to be a static resource: 'class_key => 'modStaticResource'.




          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 14 years, 2 months ago.]
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 3749
            • 24,544 Posts
            FYI, here's the code used in the modResource class set() function:

            case 'contentType' :
                            if ($v !== $this->get('contentType')) {
                                if ($contentType= $this->xpdo->getObject('modContentType', array ('mime_type' => $v))) {
                                    if ($contentType->get('mime_type') != $this->get('contentType')) {
                                        $this->addOne($contentType, 'ContentType');
                                    }
                                }
                            }
                            break;
                        case 'content_type' :
                            if ($v !== $this->get('content_type')) {
                                /** @var modContentType $contentType */
                                if ($contentType= $this->xpdo->getObject('modContentType', $v)) {
                                    if ($contentType->get('mime_type') != $this->get('contentType')) {
                                        $this->_fields['contentType']= $contentType->get('mime_type');
                                        $this->_dirty['contentType']= 'contentType';
                                    }
                                }
                            }



            ------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using.
            MODX info for everyone: http://bobsguides.com/modx.html

              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting